Important: Please read the Qt Code of Conduct -

How to calculate time remaining for QProcess?

  • Firstly, sorry for my English :D and I'm just beginning to write in Qt/C++. Right now, I'm working on my open source app called Floha (media converter).

    Basically, Floha will use ffmpeg to convert the files. But I have a problem to calculate time it will taken to finish the process (and display time remaining in real time). So I just show time elapsed when the process finished.

    Here's my source code:

    @void FlohaMain::processSlot(int a)
    // Set Status column.
    if(a == 0)
    listTableModel->setItem(iRow, new QStandardItem("Success"));
    } else {
    listTableModel->setItem(iRow, new QStandardItem("Failed"));

    // Add iRow.
    iRow = (iRow + 1);
    if(iRow == listTableModel->rowCount())
        // Calculate time.
        ui->statusBar->showMessage("Time elapsed: " + QString::number(timeElapsed.elapsed()) + "ms", 10000);
    } else {
        // Process next row.


    /*********** Functions ***********/

    void FlohaMain::processAll()
    // Set variable.
    int a;
    a = iRow + 1;
    totalRowCount = listTableModel->rowCount();

    QString status;
    statusLabel->setText(status.append("%1 / %2").arg(a).arg(totalRowCount) + " item(s) processing.");
    // Read row.
    QString presetText = listTableModel->item(iRow, 1)->text();
    QString fileText = listTableModel->item(iRow, 2)->text();
    // Translate the preset.
    QStringList configText = presetsObject->getPresetConfig(presetText);
    // Get filename.
    QFileInfo fI(fileText);
    // FFmpeg argunemts.
    QStringList ffmpegArgs;
    ffmpegArgs << "-y";
    ffmpegArgs << "-i" << fileText;
    for(int n = 2; n < configText.count(); n++)
            ffmpegArgs <<;
    ffmpegArgs << ui->outputLineEdit->text() + "/Floha - " + fI.baseName() + "." +;
    // Start FFmpeg.
    processObject = new QProcess(this);
    processObject->start("ffmpeg", ffmpegArgs);
    connect(processObject, SIGNAL(finished(int)),
            this, SLOT(processSlot(int)));


    Hope someone can help me here. By the way, you get all the source code "here":

  • Welcome to devnet

    The information has to come from the application started through QProcess. Besides very complex interaction between application and QProcess you can analyse console output of your application started. This certainly assumes that the application has a timing or process output.
    See for instance readyReadStandardOutput signal.

  • I would recommend to use the ffmpeg libraries directly instead of calling an external process. It's much more easier to get status and progress information back to your code.

  • Thanks for the answers! I'll try them.

Log in to reply