(轉載)PyQt程序退出的幾種方法

尊重版權   轉至:https://blog.csdn.net/seanyxie/article/details/5805631

 

首先看函數QApplication::setQuitOnLastWindowClosed(bool) ,該函數的作用是

This property holds whether the application implicitly quits when the last window is closed.

The default is true

即控制着當最後一個可視的窗口退出時候,程序是否退出,默認是是的

如果使用app.setQuitOnLastWindowClosed(false);然後當該出窗口close以後,ps -e查看,我們發現應用程序仍舊在運行中

 

所以當此時,如果所有的窗口都響應了close(),那麼application就退出了,

如果窗口關閉,就返回TRUE,否則返回FALSE

首先給widget發送一個QCloseEvent,如果widget接受了event,就hide,如果忽略,就什麼事情都不做,默認的是接受

 

The QApplication::lastWindowClosed() signal is emitted when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed.

當最後一個可視窗口退出時候,信號QApplication::lastWindowClosed() 被髮射,然後quit

 

當然也可以在某一個時刻,直接調用quit()方法來退出application

這裏只是說明其略微的不同

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章