Solved QDialog don't show widgets, when method show() calling
-
@Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:
@oBOXPOH ,
What are you executing?
Code of the method: { ... WaitingDialog *dlg = new WaitingDialog; dlg->show(); Sleep(10000); }
-
Never use the
Sleep()
. This is because the currently executing thread(aka. GUI) is blocking.like this:
WaitingDialog *dlg = new WaitingDialog(this); QTimer::singleShot(10000, [=, dlg]{ /* Manage what you want here. */ dlg->deleteLater(); }); dlg->setModal(true); dlg->show();
-
@oBOXPOH ,
Are you showing dialog inside thread?
-
I used Sleep() as example. If instead of Sleep() I want compute something during showing dialog, what can I do?
-
Except that you will block the main thread and thus your dialog will not show until its too late.
If you have a long computational process running you should consider maybe using QtConcurrent and wire that properly with your GUI.
-
@Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:
@oBOXPOH ,
Are you showing dialog inside thread?
I show dialog, when something button was clicked. During this dialog some computing task must execute. When this task finish, this dialog must close.
-
@oBOXPOH ,
Are you talking about progressbar?
-
@Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:
@oBOXPOH ,
Are you talking about progressbar?
Just about some dialog with text without any buttons. If it easier for you, yes, about progressbar.
-
Hi
- Just about some dialog with text without any buttons. If it easier for you, yes, about progressbar.
Its not so much about being easier.
Its a concrete class
http://doc.qt.io/qt-5/qprogressbar.htmlAlso
WaitingDialog *dlg = new WaitingDialog;
dlg->show();
Sleep(10000); <<< here u lag all of application. nothing can be drawn and u will first see dialog after 10 secs.Sleep cannot be used to simulate a workload.
-
@mrjj said in QDialog don't show widgets, when method show() calling:
Hi
- Just about some dialog with text without any buttons. If it easier for you, yes, about progressbar.
Its not so much about being easier.
Its a concrete class
http://doc.qt.io/qt-5/qprogressbar.htmlAlso
WaitingDialog *dlg = new WaitingDialog;
dlg->show();
Sleep(10000); <<< here u lag all of application. nothing can be drawn and u will first see dialog after 10 secs.Sleep cannot be used to simulate a workload.
I know! I wrote Sleep() only for example. But even in this case dlg->show() doesn't show content of the dialog, shows only title and window.
-
Ok, but you description of your issue , sounds 100% when a poster loop/sleep the main thread and
other windows shows up as empty becuase there is no time to draw the child widgets.dlg->show() doesn't show content of the dialog, shows only title and window.
Well do you call a loop or something else after you open the dialog ?
Clearly
WaitingDialog *dlg = new WaitingDialog;
dlg->show();must work and i assume the widget IN the dialog is made with UI file so all should be ok ?
There is something you are not telling :)
-
@oBOXPOH ,
WaitingDialog *dlg = new WaitingDialog;
dlg->exec();connect(dlg,SIGNAL(aborted()),dlg,SLOT(stopDialog()));
connect(yourWidget,SIGNAL(executionComplete()),dlg,SLOT(stopDialog()));void WaitingDialog::stopDialog() {
this->close();
emit aborted();
} -
@Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:
@oBOXPOH ,
WaitingDialog *dlg = new WaitingDialog;
dlg->exec();connect(dlg,SIGNAL(aborted()),dlg,SLOT(stopDialog()));
connect(yourWidget,SIGNAL(executionComplete()),dlg,SLOT(stopDialog()));void WaitingDialog::stopDialog() {
this->close();
emit aborted();
}It seems logical. I'll try. Thanks!
-
I'll say what everybody else is afraid to say. Because this is not the solution Gotham deserves but it's the one it needs right now:
just addQApplication::processEvents();
afterdlg.show();
-
@VRonin
hehe first time i seen the evil QApplication::processEvents() served with a batman quote :)) -
@VRonin said in QDialog don't show widgets, when method show() calling:
I'll say what everybody else is afraid to say. Because this is not the solution Gotham deserves but it's the one it need right now:
just addQApplication::processEvents();
afterdlg.show();
It's working! Thanks a lot! Great!