[PyQt] qApp and QApplication are not the same

Phil Thompson phil at riverbankcomputing.co.uk
Thu Oct 11 10:26:49 BST 2007


On Thursday 11 October 2007, Nahuel Defossé wrote:
> I've created my QApplication class like this:
> class MyApp(QtGui.QApplication):
>     def __init__(self, *args):
>         super(MyApp, self).__init__(*args)
>         # bla bla bla
>         mywin = MyWin()
>         mywin.show()
>         self.exec_()
>     def say_hello(self):
>         print "Hello"
>
> But, within MyWin if I call QtGui.qApp.say_hello, it says it's not
> defined... It's even worse, if I ask for QtCore.qApp's type it says
> PyQt4.QtGui.QApplication
>
> There's no cast in python, is it? How could I get extra methods I defined
> in my custom QApp class?

The easiest way is to add...

    QtGui.qApp = self

...in __init__().

Personally I always use QApplication.instance() instead of qApp.

Phil



More information about the PyQt mailing list