[Qt-interest] the problem of QProgressDialog & QProgressBar

Gan Xiebin gan.xiebin at gmail.com
Tue Jul 14 08:00:48 CEST 2009


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090714/9178c437/attachment.html 


More information about the Qt-interest-old mailing list