QDialog don't show widgets, when method show() calling
-
Hello everybody!
I have some problem. I want to make custom dialog just with message, while operation executing. Code of dialog (.cpp):
WaitingDialog::WaitingDialog(QWidget *parent) : QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowTitleHint) { mainLayout = new QHBoxLayout; textLabel = new QLabel(tr("Executing...")); mainLayout->addWidget(textLabel); setLayout(mainLayout); setWindowTitle(tr("Waiting")); } WaitingDialog::~WaitingDialog(){}
Creation of the dialog:
WaitingDialog dlg(this); //this - some custom widget dlg.show(); //some code dlg.close();
When I call show() method, in this dialog I don't see content of the dialog, except title. When I call exec() method, the dialog display correctly, but this method makes the dialog modal, but I want see this dialog during executing some task.
Thanks a lot!
SOLUTION from VRonin
Add
QApplication::processEvents();
afterdlg.show();
-
-
@oBOXPOH ,
Do not set the parent to the dailog,
WaitingDialog *dailog = new WaitingDailog;
dailog->show(); -
@Vinod-Kuntoji said in QDialog don't show widgets, when method show() calling:
@oBOXPOH ,
Do not set the parent to the dailog,
WaitingDialog *dailog = new WaitingDailog;
dailog->show();Thanks for answer!
This solution didn't help me...
-
Hi,
@oBOXPOH ,
can u use exec(), and based on the condition use close(),
As u have provided
WaitingDialog dlg(this); //this - some custom widget dlg.show(); //some code dlg.close();
remove dlg.close() and check whether u will get dialog.
Thanks,
-
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?
-
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.