[PyKDE] Quitting invokes crash handler

Jim Bublitz jbublitz at nwinternet.com
Thu Aug 29 22:02:01 BST 2002


On 29-Aug-02 Frederick Polgardy Jr wrote:
> Can anyone explain to me why, in the following app, choosing Quit
> from the File menu invokes the crash handler, but closing the
> window terminates gracefully?  Is there something about KDE or
> Python I'm unaware of?

> Relevant versions:
 
> KDE 3.0.3
> Python 2.2.1
> SIP/PyQT/PyKDE 3.3.2

I used KDE 2.1.1.
 
> Code snippet:
 
> import sys
> from qt import SIGNAL, QObject
> from kdecore import KCmdLineArgs, KApplication
> from kdeui import KMainWindow, KPopupMenu, KActionCollection,
> KStdAction
 
> class stuff(KMainWindow):
>    def __init__(self, parent = None, name = None, fl = 0):
>       KMainWindow.__init__(self, parent, name, fl)
> 
>       # create a status bar
>       self.statusBar()
> 
>       # create the menubar
>       fileMenu = KPopupMenu(self)
>       actionCollection = KActionCollection(self)
>       quitAction = KStdAction.quit(self.fileQuit,
> actionCollection)
>       quitAction.plug(fileMenu)
>       self.menuBar().insertItem(self.trUtf8("&File"), fileMenu)

The above line shouldn't run at all - 'trUtf8' is not a PyKDE
method, and KDE is compiled with Qt translation functions disabled.
You want to replace this with the static function i18n

       self.menuBar().insertItem(i18n("&File"), fileMenu)

(and add i18n to kdecore's import list)

 
>    def fileQuit(self):
>       print "About to quit..."
>       KApplication.kApplication().quit()
> 
> if __name__ == "__main__":
>    KCmdLineArgs.init(sys.argv, "stuff", "Crash Test", "0.1")
>    a = KApplication()
>    w = stuff()
>    w.show()

Comment out these two lines:

>#    a.setMainWidget(w)
>#    a.connect(a, SIGNAL("lastWindowClosed()"), w.fileQuit)

The first line is, I believe, not necessary; the second line's
effect can be accomplished by overriding 'queryExit' or
'queryClose' in the KMainWindow descendant - you can have one of
those call 'fileQuit'. I'm not sure what the problem is with the
above lines.

>    a.exec_loop()

Change the variable name 'a' to 'app' or 'ddd' or apparently any
other name with *exactly* 3 characters. You probably think I'm
either kidding or hallucinating by now - I'm not. For example, I
can get 'ddd' to work, but not 'd', 'dd', 'dddd', or 'ddddd'. I have
no explanation - other than performing an explicit test for the
length of the variable name (which I'm assuming doesn't happen) I
can't imagine how code could possibly work this way. Note that
other than 3 character variable names will run - they'll just
segfault at exit. I wish I knew where to begin looking for what
causes this, because this will be a really stupid restriction if it
proves necessary.

If I take care of those three things, it runs fine on KDE
2.1.1/PyKDE 3.3.2 - I'll try it on KDE 3.0.2 and see if there's any
difference.

Let me know if you get the same results.


Jim




More information about the PyQt mailing list