Qt modal dialog and modeless dialogs

Here Insert Picture Description
Frame mode and a non-modal box creation are the same, the key is different display methods.
The difference is as follows:

Modal dialog box (not work on other windows), modeless dialog (other windows can be operated)
modal dialog with the exec () method to display, rather than through modal dialog show () method to display.
Here we must talk about the difference between show () and exec () is,
show ():
display a non-modal dialog box. Control immediately returns to the calling function.
Pop-up window is a modal dialog box, depending on the value of the modal properties.
(Original: Shows The Dialog Control Dialog AS A modeless Immediately Returns to The Calling code..
Of The Modal Dialog Will BE ACCORDING to or modeless The value of Property The Modal.)

exec ():
Displays a modal dialog box, and lock the program until the user closes the dialog box. DialogCode function returns a result.
During the dialog box pops up, the user can not switch to other windows under the same procedure until the dialog box is closed.
(Original:. Shows at The Dialog AS A Modal Dialog, blocking an until at The the User Closes IT at The function returns A A DialogCode the Result.
The Users CAN not InterAct with the any OTHER window in at The Same, the Application an until They use Close at The Dialog.)
Here we use the code look

  		QDialog dia(this);
    	dia.resize(200,100);
      	dia.exec();
    	qDebug()<<"模态对话框创建";

        //非模态对话框创建
        QDialog * dia1 = new QDialog(this);
        dia1->show();
        dia1->setAttribute(Qt::WA_DeleteOnClose);

This code is written in a lambda expression inside, so to create a non-modal dialog box uses a new, otherwise the situation will flash across the dialog box appears, and modal dialogs that invoke the exec () method, so the case will not be fleeting, the last line of setAttribute (Qt :: WA_DeleteOnClose); so that space is created in the heap after the timely release to prevent memory leaks caused by excessive application of space (although normally impossible).

Published 212 original articles · won praise 4 · Views 8748

Guess you like

Origin blog.csdn.net/ShenHang_/article/details/104877408