[PyQt] QCoreApplication.aboutToQuit not a signal...

Phil Thompson phil at riverbankcomputing.com
Fri Dec 16 00:42:02 GMT 2016


On 15 Dec 2016, at 11:38 pm, David Cortesi <davecortesi at gmail.com> wrote:
> 
> Per the Qt docs [1], aboutToQuit is a signal emitted by QCoreApplication.
> 
> However when I attempt this in a QWidget-based class,
> 
>     class Mine( QWidget ) :
>         def __init__( self, parent ) :
>             super().__init__( Parent )
>             QCoreApplication.aboutToQuit.connect( self.quittin )

How does it know which QCoreApplication instance is emitting the signal?

> this produces an error, 'PyQt5.QtCore.pyqtSignal' object has no attribute 'connect' -- which tells me that QCoreApplication is not a signal but a PyQt signal factory (?) so, following the directions in [2]:
> 
>     class Mine( QWidget ) :
>         about_to_quit = QCoreApplication.aboutToQuit()
>         def __init__( self, parent ) :
>             super().__init__( Parent )
>             about_to_quit.connect( self.quittin )
> 
> Nope, that gets the error "native Qt signal is not callable" -- so it isn't a pyqtSignal after all, it's a real signal.
> 
> So then accidentally I entered this:
> 
>     class Mine( QWidget ) :
>         about_to_quit = QCoreApplication.aboutToQuit # <-- no parens!
>         def __init__( self, parent ) :
>             super().__init__( Parent )
>             about_to_quit.connect( self.quittin )
> 
> That executes without error! (So when it is assigned to a class variable, QCoreApplication.aboutToQuit somehow acquires a .connect attribute?)
> 
> But however alas -- no signal is delivered, or at any rate self.quittin() is never entered.
> 
> So I could use some enlightenment here...

connect() is a method of bound signals, so...

QCoreApplication.instance().aboutToQuit.connect(self.quittin)

Phil


More information about the PyQt mailing list