[PyKDE] Killing QApplication
Paul Waldo
pwaldo at waldoware.com
Mon May 1 17:34:32 BST 2006
Hi Jim,
Thanks for the reply. I'm trying to test in a slightly different way than
your method. If I understand you correctly, you create a main window and
have a button kick off all of your tests. I create a bunch of test classes,
each of which needs to be run on its own (while developing), then folded into
the master tester. I'm not sure your method would work in my situation.
I tried using KMainWindow.close() in the tearDown() method, but I still got
the "QApplication: There should be max one application object" error :-(
Maybe the unit test file you mentioned will work. If you could post it, I'd
appreciate it!
Thanks.
Paul
On Monday 01 May 2006 12:52 am, Jim Bublitz wrote:
> 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