A null program - what is it doing?

John Posner jjposner at optimum.net
Tue Jan 5 11:35:22 EST 2010


>
> No doubt a dumb question from a noob:
>
> The following program (a cut down version of some test code) uses no 
> CPU, and does not terminate:
>
> import sys
> from PyQt4.QtCore import *
>
> if __name__=="__main__":
>     app = QCoreApplication(sys.argv)
>     sys.exit(app.exec_())
>
> What is the program doing?  What is the correct way to terminate the 
> execution?
>

Are you trying to understand QCoreApplication()? I can't help you there, 
since I've never used it. If you're just trying to get started with 
PyQt, use QApplication() instead:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

if __name__=="__main__":
    app = QApplication(sys.argv)
    window = QLabel("I'm a PyQt window")
    window.show()
    sys.exit(app.exec_())

To terminate execution, just close the window by clicking the "X" in the 
window banner.

HTH,
John




More information about the Python-list mailing list