开发者

modeless QDialog: closeEvent() not called when application exits?

开发者 https://www.devze.com 2023-02-08 10:31 出处:网络
I have a modeless dialog that overrides closeEvent() in order to save its state. This works fine if I actually close the dialog. However, if I just exit the application by whatever means (which of cou

I have a modeless dialog that overrides closeEvent() in order to save its state. This works fine if I actually close the dialog. However, if I just exit the application by whatever means (which of course results in my dialog closing), closeEvent() never gets called.

Is this by design? Is it a Qt bug? Is there something like a property I开发者_运维技巧 need to set on the widget to tell it to receive close events when the application is shutting down?

I guess I can duplicate the "save state" code in the dialog's destructor, but it would be nicer if I didn't have to.

Thanks for any thoughts!


Maybe you could use a tricky solution: just call closeEvent of your dialog from closeEvent of MainWindow, passing QCloseEvent object as argument. For example:

void QtMainWindowTest::closeEvent(QCloseEvent *ev)
{
    _dlg ->closeEvent(ev);
}


There's a bug in Qt that when an application quits via menu command (instead of closing the last QMainWindow), the event system is not properly shutdown and objects on the heap are just leaked. It basically just calls exit(); right away.

I filed a bug for this on the Mac platform. I don't know what your platform is and if it's also affected.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号