PDA

View Full Version : QProgressDialog stucks



Mystical Groovy
2nd October 2009, 17:55
Hey everyone I want to use a progressdialog in busy mode to run a process

heres the code:



QProcess *installproc = new QProcess(this);

QProgressDialog progress("Installing Package...", "Cancel", 0, 0, this);
progress.setRange(0,0);
progress.setWindowModality(Qt::WindowModal);
progress.exec();

installproc->start(InstallPkgCom);

if (installproc->waitForFinished())
{
progress.close();
}


the problem is that the dialog isnt closing with the process is finished..
iv noticed that if i dont press cancel or do anythink on the dialog for about 10-15 secs, and then press cancel, the dialog closes and the process is finished

so basically the process is running just fine even after the dialog shown up, but the dialog refuses to close when the process is finished.

p.s sorry for my english :P

caduel
2nd October 2009, 18:04
you have to process events now and then (see QCoreApplication::processEvents()) if there is no (other) event loop processing

Mystical Groovy
2nd October 2009, 19:10
thanks for your answer,

i cant get it to work, i run qApp->processEvents();/QCoreApplication->processEvents();

before and after i call the qprocess, and ive also tried to run the processevents function before and after the qprogressdialog but it wont work,

any example code? xD

faldzip
2nd October 2009, 19:40
don't use waitFor* methods where you don't have to because they are blocking - as their names say - they're just waiting and doing nothing (your whole application is just waiting) until something is done. Create progress dialog on a heap and connect QProcess::finished() with QProgressDialog::close() and don't use waitForFinished() so in between your applicantion can process events.

P.S. And I'm not sure but you can set WA_DeleteOnClose attribute to the QProgressDialog...

Mystical Groovy
3rd October 2009, 00:13
i dont want to create new slots and staff so ill use the standart system() function

code ive used but its no working:


QProgressDialog progress("Installing Package...", "Cancel", 0, 0, this);
progress.setRange(0,0);
progress.setWindowModality(Qt::WindowModal);
qApp->processEvents();

while(progress.exec())
{
system ( InstallPkgCom ); //install package
}

progress.close();

caduel
3rd October 2009, 11:27
during the execution of system() the calling thread "pauses" - you can't show a QProgressDialog nor interact with it during that time. So use QProcess instead.

Mystical Groovy
3rd October 2009, 18:29
well ive tried to do ti with byconnecting qrocess::finished to QProgressDialog::close()

but it says:

Object::connect: No such signal QProcess::finished()

heres my code:

QProcess *installproc = new QProcess(this);
connect( installproc, SIGNAL(finished()),
this, SLOT(processFinished()) );

installproc->start(InstallPkgCom);

faldzip
3rd October 2009, 20:44
you can check in docs that it is: void finished ( int exitCode, QProcess::ExitStatus exitStatus )

Mystical Groovy
4th October 2009, 00:03
thank you all for your help i did it!


progress->setLabelText("Removing Package...");
progress->setRange(0,0);
progress->setWindowModality(Qt::WindowModal);

QProcess *removeproc = new QProcess(this);
removeproc->start(RemovePkgCom);
connect( removeproc, SIGNAL(finished(int,QProcess::ExitStatus)),this,SL OT(removeProcessFinished()));

progress->exec();
:D:D:D:D