QMessageBox dose not show the content
-
Hi,
I want to pop up a dialog telling the user to wait for processing. I use show() instead of exec() as I want the message box to return to the caller immediately (below is the code i used.). However, the message box only shows its frame but not any contents. (showing the residue of previous windows as in the attached image). Any idea how to solve this? The exec() works fine by the way but it only returns when the dialog is closed, which is not the use case here.
QMessageBox msgBox(QMessageBox::Information, tr("Request Destination"), "Waiting for reply ...", QMessageBox::Cancel, this); msgBox.setModal(true); msgBox.show(); QApplication::processEvents(); while (...) { dowork(); }
-
-
@dalishi said in QMessageBox dose not show the content:
I thought the processEvents() does the tricks
How can it if it's not inside the loop?
-
@JonB Thank you for bringing up progressdialog. Actually i have progressdialog in my program and the similar thing happens. For the first few steps, the progressdialog also does not show anything but frame only. Fortunately it shows the progress bar after a few more steps. I think it's also because the following processing code blocks the event loop. I'm just curious how the event loop works and how should we ask Qt to process the event at certain point.
-
This is untested, but should work as well. Without the nasty QProcessEvents.
QMessageBox msgBox(QMessageBox::Information, tr("Request Destination"),"Waiting for reply ...", QMessageBox::Cancel, this); msgBox.setModal(true); QMetaObject::invokeMethod(this, [=]()->void{ while (...) { dowork(); } }, Qt::QueuedConnection); msgBox.exec();
-
@jsulm Thanks very much. I finally got what you mean. processEvent() need to be in the loop for periodically getting called and processing the event. I just tried put it in the loop but I think this way messed up the normal event handling of Qt. The buttons and windows are not responsive any more as usual. So I will go for the second option as per your instruction. Thanks.