Progressbar showing the status of external application



  • I want to display the progress of my external application in the progressBar.....as I am new to Qt I am not aware how to proceed......kindly help me in this regard.....
    @void projectgui1::on_pushButton_clicked()
    {
    QString program = "test.exe";
    QProcess *myProcess = new QProcess(this);
    myProcess->start(program, 0);
    return ;
    }@

    i want the progressbar to show the progress of my test.exe...


  • Lifetime Qt Champion

    Hi,

    Does test.exe return a feedback somehow ? Like writing something on stdout ?



  • test.exe returns a video file modified by the user......test.exe is written in visual studio 2010



  • When the test.exe outputs its status to the stdout you are able to read that in Qt (or any other application). Without the feedback there is no way how and where the application is running.



  • I just want to get the start and end status of my external application....or simply want to show my progressbar busy while my external application is running.....



  • Aloha,

    If that's the only thing you want, why do you want to use QProgressBar.
    And I completely agree with the previous guys, that to have proper progress bar you need some feedback from the other app.

    However, since you want to show that the process is being executed. I have used those "AJAX loading gifs ":http://harpers.org/wp-content/themes/harpers/images/ajax_loader.gif in the past. Basically you already know when you execute the process. Just show a label or the gif to warn the user. And connect a signal finished() which is emitted by QProcess. And that's it, I don't think you need progress bar for that, if you don't have a proper feedback.



  • @void projectgui1::on_pushButton_4_clicked()
    {

    QString program = "test.exe";
    QProcess *myProcess = new QProcess(this);
    myProcess->start(program);
    if(myProcess->state()!=0)
      {
        static int count = 0;
        ui->progress->setMaximum(0);
        ui->progress->setMinimum(0);
        ui->progress->setValue(count++);
        ui->status->setText("Running...");
    
    }
    

    else if(myProcess->state()==0)
    {
    ui->progress->reset();
    ui->progress->setMaximum(1);
    ui->progress->setMinimum(0);
    ui->status1->setText("Finished...");
    }

    return;
    }
    @

    using the above code i was able to show the Progress Bar busy when the test.exe was executed...but when the test.exe terminates the progress bar keeps on running...How do I solve that?



  • Ok, your code doesn't make sense. Did you read my previous post? Doesn't look so.

    Basically on button click, you start your process and set your progress bar value to 1 even though your maximum and minimum is 0. From what I know, it will make the progress bar bounce from left to right.

    When you press the button, it will execute the if statements only once per CLICK. It will never execute second else if statement until you press the button again.

    And why do you have return statement at the end of void function. It will work, but it is unnecessary, since return will be called at the end of function automatically.

    By following what I said in previous post AND "QProcess":http://qt-project.org/doc/qt-5.0/qtcore/qprocess.html#finished documentation, you should have come up with something like this:

    Edit:
    By reading QProgressBar documentation

    bq. If minimum and maximum both are set to 0, the bar shows a busy indicator instead of a percentage of steps. This is useful, for example, when using QFtp or QNetworkAccessManager to download items when they are unable to determine the size of the item being downloaded.

    I can tell you that setValue for progress bar is unnecessary at the button click.
    @
    void MyClass::startProcessBtn_click()
    {
    QString program = "test.exe";
    QProcess *myProcess = new QProcess(this);
    connect(myProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(itHasFinished(int, QProcess::ExitStatus));

        ui->progress->setMaximum(0);
        ui->progress->setMinimum(0);
    
    myProcess->start(program);
    

    }

    void MyClass::itHasFinished(int exitCode, QProcess::ExitStatus exitStatus)
    {
    if(exitStatus == QProcess::NormalExit) //The application closed properly (no crash)
    {
    //Let's make progress bar to show 100%
    ui->progress->setMaximum(1);
    ui->progress->setMinimum(0);
    ui->progress->setValue(1);
    }
    }
    @

    I wrote those two functions without testing, only for guidance. What I'm trying to say, the code might not run.

    To me it looks like you have skipped very important steps when learning about Qt.
    you should check out it's "event system":http://qt-project.org/doc/qt-4.8/eventsandfilters.html and "signal/slots system ":http://qt-project.org/doc/qt-5.0/qtcore/signalsandslots.html otherwise you won't be able to program in Qt.



  • Oke,
    The above code looks nice, but what might go wrong is that QProcess is deleted (leaving startProcessBtn_Click()) because the owner is the current class. When the function gets therminated the QProcess might as well killing your application before it is finished. Might need the startDetached option.
    But I might be mistaken when it comes to QProcess. Have used it ones before ;-)



  • jeroentje,

    Actually I've never used QProcess, but if that's the case, then one might skip using signals and use waitFor... methods aswell I guess.

    It would look something like this:

    @
    void MyClass::startProcessBtn_click()
    {
    QString program = "test.exe";
    QProcess *myProcess = new QProcess(this);

        ui->progress->setMaximum(0);
        ui->progress->setMinimum(0);
    
    myProcess->start(program);
    
     if (!myProcess->waitForStarted()) //by default timeout is 30000 ms
     {
          //Process couldn't be started !!!!
        return;
     }
    
    if (!myProcess->waitForFinished()) //by default timeout is 30000 ms
    {
        //Process execution took more than 30000 ms       
       //Do error handling
     }
    
            //Let's make progress bar to show 100%
            ui->progress->setMaximum(1);
            ui->progress->setMinimum(0);
             ui->progress->setValue(1); 
    

    }

    @

    Again not stating that the above code will work, just guessing, that's the fun of programming finding 100 ways of doing things. But If I could, I always like using signals as much as I can.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.