0

I have a QFutureWatcher connected to a QProgressBar, the code is running but never show me the progress of the progressBar

QProgressDialog progress;
QFutureWatcher<void> watcher;

connect(&watcher, SIGNAL(finished()),&progress, SLOT(reset()));
connect(&watcher, SIGNAL(progressRangeChanged(int, int)),&progress, SLOT(setRange(int,int)));
connect(&watcher, SIGNAL(progressValueChanged()),&progress, SLOT(setValue(int)));
QFuture<int> file = QtConcurrent::run(aFunction, cmd);
watcher.setFuture(file);
progress.exec();
watcher.waitForFinished();
int aFunction(string cmd){
  int status;
  status= system(cmd.c_str());
  return status;
}

this is the code I have, the result just show me a full progress bar, I want to see from 0 to 100 enter image description here

drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • 2
    The `system()` doesn't return before the `cmd` is done. It won't work this way. To manage progress of a child process, you better investigate into `QProcess`. Furthermore, the return value of a program is not sufficient for this. Instead, you could read output from the stdout / stderr of the child process to manage progress somehow. FYI: [Creating QT Application as GUI for existing console-based application on windows](https://stackoverflow.com/a/45209503/7478597) – Scheff's Cat Jan 18 '23 at 06:18
  • @Scheff'sCat thanks for your answer, there's a way to run QProcess with the full cmd instead this `QProcess sh; sh.start("sh", QStringList() << "-c" << "ifconfig | grep inet");` cause I don't know what can be at my cmd string I just run it – Pepe Arzate C Jan 18 '23 at 15:37
  • It might be that you have to provide the full path to your executable in `start()`, e.g. `"/bin/sh"`. I tried to find info in the doc. whether `QProcess::start()` consults the environment (e.g. `PATH`) but I couldn't find anything. I guess it does not. – Scheff's Cat Jan 18 '23 at 18:27

0 Answers0