[Qt-interest] the problem of QProgressDialog & QProgressBar
John McClurkin
jwm at nei.nih.gov
Tue Jul 14 15:05:52 CEST 2009
John McClurkin wrote:
> Malyushytsky, Alex wrote:
>> >> But the progress dialogue only shows after( or at the same time)
>> THE SysInfo Dialogue.
>> >> WHY??
>>
>> Because of p_ShowSysInfoDlg->exec(); I guess.
>>
>> I don’t think event loop of application is running when you open
>> another modal dialog.
>>
>>
>>
>> Regards,
>>
>> Alex
>>
>>
>>
>> * *
>>
>> * *
>>
>> *From:* qt-interest-bounces at trolltech.com
>> [mailto:qt-interest-bounces at trolltech.com] *On Behalf Of *Gan Xiebin
>> *Sent:* Monday, July 13, 2009 11:01 PM
>> *To:* qt-interest
>> *Subject:* Re: [Qt-interest] the problem of QProgressDialog &
>> QProgressBar
>>
>>
>>
>> Hi Alex,
>>
>> Thanks for reply.
>> I have a code like that,
>>
>> ----------------------
>> void MainWindow::SysInfoFunc()
>> {
>> SysInfoDlg *p_ShowSysInfoDlg = new SysInfoDlg( );
>> p_ShowSysInfoDlg->exec();
>> }
>>
>> SysInfoDlg::SysInfoDlg(QWidget *parent)
>> : QDialog( parent )
>> {
>> 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( ... );
>>
>> }
>> ------------------------------------
>>
>>
>> I must ensure that the application does not freeze.
>> I read the document carefully, and used QProgressDialog ...
>>
>> ---------------------------------------------
>> void MainWindow::SysInfoFunc()
>> {
>>
>> progressDlg = new QProgressDialog("Operation in progress.",
>> "Cancel", 0, 100, this);
>> connect(progressDlg, SIGNAL(canceled()), this,
>> SLOT(cancelProgressDlg()));
>> timer = new QTimer(this);
>> connect(timer, SIGNAL(timeout()), this, SLOT(performProgressDlg()));
>> timer->start(0);
>>
>> progressDlg->setValue(0);
>> SysInfoDlg *p_ShowSysInfoDlg = new SysInfoDlg(node);
>> p_ShowSysInfoDlg->exec();
>>
>> progressDlg->setValue(progressDlg->maximum());
>>
>> }
>>
>> void MainWindow::cancelProgressDlg()
>> {
>> timer->stop();
>> progressDlg->close();
>> }
>>
>> void MainWindow::performProgressDlg()
>> {
>> if(progressDlg->value() + 1 < progressDlg->maximum())
>> {
>> progressDlg->setValue(progressDlg->value() + 1);
>> }
>> else
>> {
>> timer->stop();
>> progressDlg->close();
>> }
>>
>> qApp->processEvents(); }
>> --------------------------------
>>
>>
>> But the progress dialogue only shows after( or at the same time) THE
>> SysInfo Dialogue.
>> WHY??
>>
>> P.S. : I used the model dialogue of QProgressDialog, but have no
>> effect for me.
>>
>> Thanks.
>
> 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.
More information about the Qt-interest-old
mailing list