[PyKDE] qApp is a QApplication instance

Giovanni Bajo rasky at develer.com
Mon Mar 21 15:15:12 GMT 2005


Phil Thompson <phil at riverbankcomputing.co.uk> wrote:

>>>> Is this expected / wanted? I had expected to be able to access the
>>>> Python
>>>> instance of the application through the global qApp, not the
QApplication.
>>>> In Qt, I can down-cast the qApp pointer to my subclass to access my
>>>> methods,
>>>> how can I do the same in PyQt?
>>>
>>> sys.modules['qt'].__dict__['qApp'] = A(sys.argv)
>>>
>>> ...might do it. You have to make sure that this is done before the other
>>> modules that want to use it get imported.
>>
>>
>> I'll try that, thanks.
>>
>> Would you consider this behaviour a bug, and in that case, is it feasable
>> to
>> fix it?
>
> No, it's not a bug.

Well, I'm trying, but it's almost impossible to do it. By the time the App
constructor has executed, many modules are imported already. Even putting
the sys.modules line at the top of A's constructor is not enough because of
the fact that many modules are already imported. I even tried reload the
modules but that caused other problems.

I understand that you consider this not stricly a bug. But there *is* a need
to access the application from everywhere without passing it around, and
qApp exists exactly for that. In C++, you can downcast it to whatever app
type you defined and use it. This is impossible with PyQt. So, you should at
least consider providing a different global for accessing the Python's
application (pyApp?), as there is really no easy way to do it manually.
-- 
Giovanni Bajo




More information about the PyQt mailing list