简体   繁体   中英

How run a progress bar to indicate the other process is busy in Qt

I am working on a project and I need to show the User a 'busy progress bar' or a 'GUI element' until another process is completed. Is there any way I can do it without using threads. The snippet as shown:

     QProcess compile;
     QProgressDialog *dialog = new QProgressDialog();
     dialog->setMinimum(0);
     dialog->setMaximum(0);

     compile.start("make", QStringList()<< send.at(2) << "-j6" << "IN=" + QFileInfo(send.at(0)).absolutePath() + "/" +QFileInfo(send.at(0)).baseName() << "OUT=/home/venkatesh/MooNMD_Working/ParMooN_Out/cd2d/" + send.at(1) + ".exe" << "&");
     while(compile.waitForFinished(-1))
     {
          dialog->exec();
     }
     dialog->close();

But the busy progress bar does not close on it's own at the end of make command. What are my options?

You should do something like this:

QProcess compile;
QProgressDialog *dialog = new QProgressDialog;
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setRange(0,0);
connect(&compile, SIGNAL(finished(int)), dialog, SLOT(close()));

compiler.start("myprog.exe");
dialog->exec();

Having dialog->exec(); in a loop makes no sense. It will also block when you call dialog->exec(); meaning your loop won't finish.

The QProgressDialog will only close when the value passed to setValue reaches the value set by setMaximum .

You have set both the minimum and maximum to be 0 so obviously the dialog will not function properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM