iMath
iMath

Reputation: 2478

How to implement the "exit" action in PyQt4?

Many software have an "exit" action in the menubar items. I wonder know how to implement it in pyqt4.

I think only invoking the method QtCore.QCoreApplication.quit() is not enough, because the application main window doesn’t disappear immediately when this method is called.

I think in order to "exit", we shouldn’t only call the quit() method but also should close the application main window at the same time.

What do you think ?

Upvotes: 3

Views: 1251

Answers (1)

ekhumoro
ekhumoro

Reputation: 120798

By default, the application will quit when the last window is closed - unless quitOnLastWindowClosed has been set to False.

So it is normally enough to just call close() on the main window.

One other thing to think about here, though, is whether any final actions should be taken before the application closes down (e.g. saving settings, asking the user whether they want to save any modified documents, etc).

So it is also common to reimplement the main window's closeEvent function.

Upvotes: 2

Related Questions