I have a question that has an obvious answer for some of you, but I just can't figure it out.
QMessageBox http://qt-project.org/doc/qt-5/qmessagebox.html has 2 ways to display, either you execute exec() , which stop the program until the user closes the message box, or show() , which they display only the field (possibly in a separate thread or in some way, which allows the program to continue working while the window is waiting for the user).
How to delete a field after using show ()?
This code will immediately close it, a message box for a nanosecond will appear, and then it disappeared:
QMessageBox *mb = new QMessageBox(parent); mb->setWindowTitle(title); mb->setText(text); mb->show(); delete mb;
this code does the same
QMessageBox mb(parent); mb.setWindowTitle(title); mb.setText(text); mb.show(); // obvious, as we exit the function mb which was allocated on stack gets deleted
also this code does the same
QMessageBox *mb = new QMessageBox(parent); mb->setWindowTitle(title); mb->setText(text); mb->show(); mb->deleteLater();
So, how can I use show () correctly without having to handle its removal in some complicated way? Is there something like the deleteOnClose() function that just says that it will delete itself when the user closes it?
source share