Solved QDialog don't show widgets, when method show() calling
-
Hi,
Can you show the complete method code where you create that dialog ?
-
hi,
And u said u need to get the dialog on perform of some task, can u specify the situation ?. when u need and based on that, u can call the dialog in slot.
Thanks,
-
Comrades! What I have got:
WaitingDialog dlg(this); //this - some custom widget dlg.show(); // some code (without other dialogs)
I delete dlg.close(), but there is changed nothing.
WaitingDialog dlg = new WaitongDialog; dlg->show(); // some code
I create dialog without parent and just show this dialog. In the beginning of execution (when Qt calls dialog) I see the dialog only with title, but when the execution of some code finished (I'm not close dlg (dlg->close()), the content of the dialog became visible.
In code I don't call to dialogs, just compute some values.
Strangely!
-
@SGaist said in QDialog don't show widgets, when method show() calling:
Hi,
Can you show the complete method code where you create that dialog ?
Code of the dialog:
WaitingDialog::WaitingDialog(QWidget *parent) : QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowTitleHint) { mainLayout = new QHBoxLayout; textLabel = new QLabel(tr("Processing...")); mainLayout->addWidget(textLabel); setLayout(mainLayout); setWindowTitle(tr("Waiting")); } WaitingDialog::~WaitingDialog(){}
Code of the method:
{ ... WaitingDialog *dlg = new WaitingDialog; dlg->show(); Sleep(10000); }
In the beginning the dialog show only title. After 10 seconds I get management of parent (where I use this code) and content of the dialog (QLabel) in this dialog. I.e. get content only after Sleep!
-
@oBOXPOH ,
What are you executing?
-
@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 :))