开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜