A null program - what is it doing?

G

Gib Bogle

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?

Thanks in advance for educating me.
 
R

r0g

Gib said:
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?

Thanks in advance for educating me.



I've never used QT but other graphical toolkits I have used all start
their own "main loop" which is a loop that cycles round receiving,
queuing and dispatching "events". You probably need to call the
QCoreApplication's quit method to break out of this e.g.

app.exit() or something similar, have a look at some complete PyQt4
examples or google for PyQt4 mainloop.


Roger.
 
D

Dave Angel

r0g said:
I've never used QT but other graphical toolkits I have used all start
their own "main loop" which is a loop that cycles round receiving,
queuing and dispatching "events". You probably need to call the
QCoreApplication's quit method to break out of this e.g.

app.exit() or something similar, have a look at some complete PyQt4
examples or google for PyQt4 mainloop.


Roger.
Likewise, I haven't used QT, but have used others.

Gib:

It looks like app.exec() is the mainloop for QT, and it won't terminate
till it gets a terminate event. That might be the user clicking the X
in the corner, or it might be a special keystroke like Alt-F4. Or it
might be some other event for which your event handler makes an explicit
call to terminate. Once one of these things happens, the app.exec()
will return, and the sys.exit() will execute.

DaveA
 
G

Gib Bogle

r0g said:
I've never used QT but other graphical toolkits I have used all start
their own "main loop" which is a loop that cycles round receiving,
queuing and dispatching "events". You probably need to call the
QCoreApplication's quit method to break out of this e.g.

app.exit() or something similar, have a look at some complete PyQt4
examples or google for PyQt4 mainloop.


Roger.

Thanks. I've realized that QCoreApplication (or QApplication) manages the event
loop, and normally when it is executed you are showing a widget of some kind,
closing which ends the application. Alt-F4 acts like Ctrl-C to terminate from
the keyboard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top