[Qt-interest] qprocess related with qprogressbar

Sean Harmer sean.harmer at maps-technology.com
Sat Jun 27 10:31:27 CEST 2009


Hi,
mierdatutis mi wrote:
> Many thanks again.
> I put in my shell script, some outpouts to stdout that the function
> that read all the output of the script can compare the string and can
> increment the progress bar.
> The problem that I have is that the progressbardialog dissapear every
> time that the program enter in the output capture. Could I do that the
> progressbar is always on top?
>
> Many thanks
>
> This is the code:
>
> void MainWindowImpl::salida()
> {
> 	QStringList strs;
> 	
>     QByteArray result=proc2->readAllStandardOutput();
>     qDebug() << proc2->readAllStandardOutput();
>
>     QStringList lines = QString(result).split("\n");
>     foreach (QString line, lines) {
>         texto->append(line);
>         qDebug() << line;
>
>     QProgressDialog progress("DESCARANDO SINOPSIS...", "&Wake Up!", 0, 7, 0);
>   
This is your problem. You are creating a QProgressDialog on the stack so 
that when the execution reaches the end of this function and the stack 
is cleaned up the dialog will get destroyed.

Instead what you could do it make pointer to a QProgressDialog a member 
of your class, create it either in the constructor but do not show it at 
this point. Show it from a slot that gets called when the process has 
started. Then call setValue in your slot that processes the output of 
your script. If you create the progress dialog with your main window as 
its parent, then their is no need to ever explicitly delete it as the Qt 
object model will do this for you. However, you will need to hide the 
dialog when the process finishes. Once again this can be done in a slot 
connected to the QProcess::finished() signal.

Good luck,

Sean




More information about the Qt-interest-old mailing list