connect QProcess with QProgressbar

1k views Asked by At

i have this code but it is not working.i am trying to update progressbar while my video is converting.video conversion is fine but progessbar is not updating

void MainWindow::on_pushButton_clicked()
{
QString alienpath="ffmpeg";
QStringList argument;

argument<<"-i"<<ui->lineEdit->text()<<"/home/suraj/a.flv";
QProcess *alien=new QProcess(this);
alien->start(alienpath,argument);
int p;
p=alien->readAll().toInt();
ui->progressBar->setMaximum(0);
ui->progressBar->setMinimum(100);
ui->progressBar->setValue(p);
}

plz help

1

There are 1 answers

0
Oleg Pyzhcov On BEST ANSWER
  • First, your progressbar seems to be never updated after it was configured in your code. You may want to use QTimer or readyRead/readyReadStandardOutput signal connecting to some slot in MainWindow or C++11 lambda, but I'm not sure what the output will contain in each time, so I can't tell if this will work.
  • Second, your toInt() is likely to fail. It works only if your output contains pure number like 67; the application usually produces a lot of output. Use QRegExp or QRegularExpression (Qt5) to extract digits and convert only them. toInt() supports checking if a conversion error has occured, see documentation.