QMessageBox non blocking
-
wrote on 29 Sept 2021, 09:45 last edited by
I would like to display a simple QMessageBox that is non blocking that is present whilst my application works in the background, I have added an instance of QMessageBox to my class and before the work starts:
mmsgBox.setText(tr("Scanning file, please wait...")); mmsgBox.setWindowModality(Qt::NonModal); mmsgBox.exec();
Calling exec causes the message box to be displayed with the text visible but execution is halted until the message box is closed. If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.
What do I need to do to resolve this?
-
I would like to display a simple QMessageBox that is non blocking that is present whilst my application works in the background, I have added an instance of QMessageBox to my class and before the work starts:
mmsgBox.setText(tr("Scanning file, please wait...")); mmsgBox.setWindowModality(Qt::NonModal); mmsgBox.exec();
Calling exec causes the message box to be displayed with the text visible but execution is halted until the message box is closed. If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.
What do I need to do to resolve this?
-
I would like to display a simple QMessageBox that is non blocking that is present whilst my application works in the background, I have added an instance of QMessageBox to my class and before the work starts:
mmsgBox.setText(tr("Scanning file, please wait...")); mmsgBox.setWindowModality(Qt::NonModal); mmsgBox.exec();
Calling exec causes the message box to be displayed with the text visible but execution is halted until the message box is closed. If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.
What do I need to do to resolve this?
wrote on 29 Sept 2021, 09:52 last edited by JonB@SPlatten said in QMessageBox non blocking:
If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.
That is the right thing to do, but I don't know why the text does not show. See https://stackoverflow.com/questions/49266964/how-to-make-qmessagebox-non-modal for solutuon claiming it works. Don't know your platform or if that makes any differnce. With
show()
have you made sure yourmmsgBox
's scope persists (should be OK if the leadingm
implies class member variable)? [Oh, just seen you say it is class-wide.] Or https://stackoverflow.com/questions/3211490/how-to-make-a-non-blocking-non-modal-qmessagebox claims it works withQMessageBox::open()
rather thanshow()
.@Sai-Raul said in QMessageBox non blocking:
QMessageBox::information (this, "Scanning file, please wait...");
Docs state:
The message box is an application modal dialog box.
OP wants a modeless/non-modal message box.
-
@SPlatten said in QMessageBox non blocking:
If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.
That is the right thing to do, but I don't know why the text does not show. See https://stackoverflow.com/questions/49266964/how-to-make-qmessagebox-non-modal for solutuon claiming it works. Don't know your platform or if that makes any differnce. With
show()
have you made sure yourmmsgBox
's scope persists (should be OK if the leadingm
implies class member variable)? [Oh, just seen you say it is class-wide.] Or https://stackoverflow.com/questions/3211490/how-to-make-a-non-blocking-non-modal-qmessagebox claims it works withQMessageBox::open()
rather thanshow()
.@Sai-Raul said in QMessageBox non blocking:
QMessageBox::information (this, "Scanning file, please wait...");
Docs state:
The message box is an application modal dialog box.
OP wants a modeless/non-modal message box.
wrote on 29 Sept 2021, 10:06 last edited by@JonB said in QMessageBox non blocking:
QMessageBox::open()
With regards to that part: exec() spins up another event loop while open() does not. Can't tell about show(). So I think it's just try and test situation...
-
@SPlatten said in QMessageBox non blocking:
If I replace exec with show then the message box is displayed and it doesn't halt which is what I want and need but its empty and the text isn't showing.
That is the right thing to do, but I don't know why the text does not show. See https://stackoverflow.com/questions/49266964/how-to-make-qmessagebox-non-modal for solutuon claiming it works. Don't know your platform or if that makes any differnce. With
show()
have you made sure yourmmsgBox
's scope persists (should be OK if the leadingm
implies class member variable)? [Oh, just seen you say it is class-wide.] Or https://stackoverflow.com/questions/3211490/how-to-make-a-non-blocking-non-modal-qmessagebox claims it works withQMessageBox::open()
rather thanshow()
.@Sai-Raul said in QMessageBox non blocking:
QMessageBox::information (this, "Scanning file, please wait...");
Docs state:
The message box is an application modal dialog box.
OP wants a modeless/non-modal message box.
-
@JonB said in QMessageBox non blocking:
QMessageBox::open()
With regards to that part: exec() spins up another event loop while open() does not. Can't tell about show(). So I think it's just try and test situation...
-
@JonB , just tried this, still the same, calling open instead of show doesn't block but neither does it open the dialog with the text being displayed.
-
wrote on 29 Sept 2021, 11:42 last edited by mpergand
I made some test on Mac.
QMessageBox box; box.setText("hello"); box.move(30,30); box.open(); box.raise();
It works but the msgbox appears behind QtCreator and so hidden !
What's the reason why i add box.raised()
Everything seems ok, i can interact with other windows, and the default OK button closes the msgbox. -
@JonB , just tried this, still the same, calling open instead of show doesn't block but neither does it open the dialog with the text being displayed.
wrote on 29 Sept 2021, 11:44 last edited by@SPlatten I suspect that the cause is that
mmsgBox
is a local variable, a basic C++ rule: what happens to a local variable when the function where it is used is finished executing? Well, they are eliminated. The solution could be to extend its scope for example by making a member of the class. -
@SPlatten I suspect that the cause is that
mmsgBox
is a local variable, a basic C++ rule: what happens to a local variable when the function where it is used is finished executing? Well, they are eliminated. The solution could be to extend its scope for example by making a member of the class.wrote on 29 Sept 2021, 11:44 last edited by SPlatten@eyllanesc , No it isn't mmsgBox is a class member, 'm' = member.
-
@eyllanesc , No it isn't mmsgBox is a class member, 'm' = member.
-
wrote on 6 Aug 2023, 10:18 last edited by
Try using QApplication::processEvents() after show() and before the work starts. This solved the issue for me.