[PyQt] QtGui.QApplication() never returns

David Boddie dboddie at trolltech.com
Mon Dec 14 14:15:21 GMT 2009

On Sat Dec 12 21:47:16 GMT 2009, Joe Turpin wrote:

> I have a very basic python script file that looks like the following
> (taken directly from an online tutorial):
>     #!/usr/bin/python
>     # simple.py
>     import sys
>     from PyQt4 import QtGui
>     app = QtGui.QApplication(sys.argv)
>     widget = QtGui.QWidget()
>     widget.resize(250, 150)
>     widget.setWindowTitle('simple')
>     widget.show()
>     sys.exit(app.exec_())
> The script runs to completion when I execute it under my regular user
> account, but hangs when I execute it as root.. Using pdb I inserted a
> set_trace() and found that it never returns from the call to
> QtGui.QApplication(). Any ideas why this might be happening?

Can you give us some more information about your system's configuration
(operating system, versions of Python, Qt and PyQt) and describe what
happens in a bit more detail? For example, I presume that the window is
shown when you run the script as root and that you close it as normal.
Is that correct?

I guess you could try and run the whole thing using gdb to see where in
Qt it is hanging, though that would require the debug version of Qt to be

  gdb python
  set arg simple.py

  ... some time later hit Ctrl-C and examine the backtrace ...

An alternative would be to run the script using strace to see if it's hanging
when trying to open some file or device:

  strace python simple.py


More information about the PyQt mailing list