[PyQt] After MessageBox app quits...why?
David Boddie
david at boddie.org.uk
Thu Oct 27 21:41:26 BST 2016
On Thu Oct 27 18:20:05 BST 2016, Demosthenes Koptsis wrote:
> Hello, i have a PyQT systray app with a menu and two actions.
>
> Action1 is Exit and action2 display a MessageBox with Hello World message.
>
> When i click OK to MessageBox app quits...why?
It's due to an obscure feature of QApplication that, by default, exits the
application when the last window is closed. You can turn it off in your
program by calling
app.setQuitOnLastWindowClosed(False)
after you create the QApplication instance.
The feature was introduced to prevent certain kinds of applications from
lurking in the background after all their windows had been closed. In your
case, you create a window but never open it, so I expect QApplication just
treats the message box as the only window that the application uses.
David
More information about the PyQt
mailing list