[PyKDE] Killing QApplication

Jim Bublitz jbublitz at nwinternet.com
Mon May 1 05:52:12 BST 2006


On Sunday 30 April 2006 06:22, Paul Waldo wrote:
> Hi all,
>
> I'm trying to be a good boy, so I have a lot of unit tests for my python
> KDE application.  Each of the tests run fine individually, but when I run
> them all together, it seems that the application refuses to die.  The first
> test runs fine, but then subsequent tests give this message:
>
> QApplication: There should be max one application object

PyKDE used to have unit tests (and probably still should have). I can mail you 
a file if you like. It's about 3 years old, but mostly works on the current 
PyKDE.

The way I did it was to create a single KApplication with a KMainWindow, and 
run all the tests in that environment, initiated with a push button. In that 
case (having a KMainWindow), the easiest way to shut down the KApplication is 
to call the KMainWindow's close() method. IIRC, that also allows for querying 
before closing. It turns out though that in my unit test app, I just called 
sys.exit(0) at the end of testing - not sure anymore if that's significant or 
just lazy.

There have always been problems using KApplication.quit or .exit. I don't 
recall all of the details, but it stems from a couple of things: one is the 
way the close sequence is split between KMainWindow, KApplication, and their 
Qt parent classes - it becomes difficult or impossible, IIRC, to make PyKDE 
work with all possible scenarios.

Another problem is the sequence in which objects get destroyed. Again, IIRC, 
there used to be handwritten code in both PyQt and PyKDE that made this 
happen correctly - it appears PyQt no longer requires this, and the PyKDE 
code quit working a long time ago. PyKDE could probably be modified to make 
KApplication.quit work, but then KMainWindow.close and it's associated query 
stuff wouldn't work - I believe that's the problem that didn't have any easy 
solution. 

Since nearly any PyKDE user application will have a main window of some sort, 
and since there's a "lastWindowClosed" signal that works correctly, it seems 
reasonable to have that stuff work for PyKDE. It would be possible to give 
each of your KApps a hidden KMainWindow, and the push button click is only 
important because it generates a signal that calls a slot that closes the 
KMainWindow.

Jim




More information about the PyQt mailing list