简体   繁体   中英

How to handle Qt5 close event for termination?

I have an application, which consists of two, apparently independent windows. Window A loads the data and shows some log, state info; opens Window B, where interactive processing takes place. To prevent accidental closing, in BI have an event handler, shown below. It works fine, however, it also prevents Window A to close it upon termination. Is there a better method, than using a public slot in B, and send a message through it by A, that now window B can really be closed? (or to distinguish terminating the application and closing one of the windows?)

void B::closeEvent(QCloseEvent *event)
{
     QMessageBox::warning(this, tr("Application"),
                 tr("Can only be closed through closing the main window.!"),
                     QMessageBox::Ok );
        event->ignore();
}

您可以通过修改其窗口标志来禁用一个窗口的关闭按钮

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM