Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to calculate time remaining for QProcess?
Forum Updated to NodeBB v4.3 + New Features

How to calculate time remaining for QProcess?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fahmy
    wrote on last edited by
    #1

    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);
        enableButtons();
    } else {
        // Process next row.
        processAll();
    }
    

    }

    /*********** 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++)
    {
        if(!configText.at(n).isEmpty())
        {
            ffmpegArgs << configText.at(n);
        }
    }
    
    ffmpegArgs << ui->outputLineEdit->text() + "/Floha - " + fI.baseName() + "." + configText.at(1);
    
    // 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":https://launchpad.net/floha.

    Stay hungry, stay foolish.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #3

        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.

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Fahmy
          wrote on last edited by
          #4

          Thanks for the answers! I'll try them.

          Stay hungry, stay foolish.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved