[PyKDE] QtGui.qApp does not correlate with QCoreApplication.instance()

Phil Thompson phil at riverbankcomputing.co.uk
Mon Jul 3 20:29:12 BST 2006


On Monday 03 July 2006 1:56 pm, Arve Knudsen wrote:
> Hi
>
> On Windows XP, with PyQt-4.0 and Qt-4.1.4 I am experiencing what must
> surely be a bug. Before I have instantiated any QApplication,
> QtGui.qApp already exists although QCoreApplication.instance() is None
> (as I would expect!). After I create my own QApplication,
> QCoreApplication.instance() returns a reference to this object, but
> qApp still refers to the same dummy object (the initial qApp does not
> appear functional).

It's a feature of the way Qt implements qApp and the fact that modules are 
second class citizens in Python.

Because Python modules don't have __getattr__ like methods, global objects 
(like qApp) have to be created with the correct type when the module is 
imported - even though the C++ instance they are wrapping doesn't exist yet. 
There is a level of indirection happening that means that the C++ instance 
that qApp uses is always correct and the same as that returned by 
QCoreApplication.instance(). In other words, the object returned by 
instance() and the qApp object are different object but wrap the same C++ 
instance.

What makes you say that the initial qApp does not appear functional? It's used 
all over the examples.

Phil




More information about the PyQt mailing list