Modal is when the child window pops up, the focus is always forced to focus on the child window, as long as the child window does not exit, the focus will not be released. The non-modal is just the opposite.
From the thread perspective, the modal Subwindow thread is blocked, and the parent and child windows each have a thread, and when the child window is created, the parent thread blocks off the quilt thread, the non-modal thread is not blocked, and the parent and child threads can run in parallel.
In the modal of Qt, the Qdialog exec () method is used mainly:
| 12345678910 |
SonDialog dlg(this);intres = dlg.exec();if(res == QDialog::Accepted){ QMessageBox::information(this, "INFORMATION", "You clicked OK button!");}if(res == QDialog::Rejected){ QMessageBox::information(this, "INFORMATION", "You clicked CANCEL button!");} |
The return value of the exec () determines which button the user is triggering.
Non-modal, mainly used in the Qdialog Show () method:
| 123 |
SonDialog *dlg;dlg = newSonDialog(this);dlg->show(); |
Transferred from: http://blog.csdn.net/zhy282289/article/details/6741356
Http://www.cnblogs.com/weiweiqiao99/archive/2011/05/19/2050887.html
The relationship between modal and non-modal is recorded first:
Both 1.QDialog and qwidget can be modal and non-modal.
EXEC (), Show ()
Whether the modal is independent of the two functions, only related to window properties
SetAttribute (Qt::wa_showmodal, True) or setwindowmodality (qt::applicationmodal), modifying whether it is modal.
For Qdialog You can also use his member function Setmodal (TRUE) (Dlg->show modal);
EXEC () is modal because he first set the window properties: SetAttribute () again show (see source)
2. Whether a qwidget is a form or a control on a form regardless of the parent class, only related to the window tag: setwindowflags (Qt::window)
Qpushbutton * ppushbtn = new Qpushbutton (this);
Qpushbutton * ppushbtn = new Qpushbutton (when there is no parent class, the constructor adds a Qt::window tag)
Qdialog * dlg = new Qdialog (this), regardless of whether or not the parent class is a form, because QT is passed when a parameter is transmitted to the Qwidget: the:D ialog tag.
So make the form only with Setwindowflags (Qt::window);
Qt modal and non-modal