[Qt-interest] the problem of QProgressDialog & QProgressBar
Gan Xiebin
gan.xiebin at gmail.com
Wed Jul 15 10:26:59 CEST 2009
Malyushytsky, Alex wrote:
> Because of p_ShowSysInfoDlg->exec(); I guess.
>
> I don’t think event loop of application is running when you open another
> modal dialog.
>
John McClurkin wrote:
> Alex is correct. calling p_ShowSysInfoDialog->exec() blocks the
> application until it returns. If you want the progress dialog to show
> progress during the execution of the SysInfoDialog, create the progress
> dialog first on the heap and pass a pointer to the SysInfoDialog
> constructor. Then, in the SysInfoDialog exec function, update the
> progress dialog periodically and call QApplication::processEvents().
> I forgot to add that you show() the progress dialog in the SysInfoDialog.
Thanks Alex and John.
OK. The exec() blocks the application until it returns.
But although I create the progress dialogue and pass a pointer to the
SysInfoDialog constructor,
the GUI thread still blocks while I used wait() in the event loop, right ?
What should I do ?
Any reply is welcome. Thanks.
-------------------------------------------------
void MainWindow::SysInfoFunc()
{
progressDlg = new QProgressDialog("Operation in progress.", "Cancel", 0,
100, this);
SysInfoDlg *p_ShowSysInfoDlg = new SysInfoDlg(node, progressDlg);
p_ShowSysInfoDlg->exec();
}
ysInfoDlg::SysInfoDlg(Node *node, QProgressDialog *progressDlg, QWidget
*parent)
: QDialog( parent )
{
this->progressDlg = progressDlg;
this->progressDlg->setValue(0);
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(performProgressDlg()));
timer->start(1000);
this->progressDlg->show();
QApplication::processEvents();
// set text
textLabel = new QLabel();
thread1.start(); // A task
thread2.start(); // Another task
thread1.wait(); // wait for task finished, and set text to the label
thread2.wait(); // like thread1 ...
textLabel->setText( ... );
// close dialog
timer->stop();
this->progressDlg->close();
}
void SysInfoDlg::performProgressDlg()
{
if(progressDlg->value() + 1 < progressDlg->maximum())
{
progressDlg->setValue(progressDlg->value() + 1);
}
else
{
timer->stop();
progressDlg->close();
}
progressDlg->show();
QApplication::processEvents();
}
--------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090715/67487f7b/attachment.html
More information about the Qt-interest-old
mailing list