How Can I Run QProcess on Linux?
-
I wrote a command like below, but it doesn't work, I think I did it wrong and there were points I missed. The command doesn't work at all. The output is right below.
QProcess process; QString commandq = "-c "; commandq = commandq + "echo 'hello' >> /home/winfried/text.txt;"; process.start("bash", QStringList() << commandq);
Output:
QProcess: Destroyed while process ("bash") is still running.
-
@HerrWinfried
YourQProcess process;
variable goes out of scope while the process has been started but not yet finished.For now, just put a
process.waitForFinished()
immediately after theprocess.start()
. Later do it with signals and slots, but bear the lifetime scope in mind.Your command arguments are wrong. You will need:
process.start("bash", QStringList() << "-c" << "echo 'hello' >> /home/winfried/text.txt;");
-
@HerrWinfried said in How Can I Run QProcess on Linux?:
`QProcess: Destroyed while process ("bash") is still running.
The message is explicit, you declare QProccess as local variable so it is destroyed at the end of the method where it is.
Adding process.waitForFinished after process.start should work.
-
@HerrWinfried
YourQProcess process;
variable goes out of scope while the process has been started but not yet finished.For now, just put a
process.waitForFinished()
immediately after theprocess.start()
. Later do it with signals and slots, but bear the lifetime scope in mind.Your command arguments are wrong. You will need:
process.start("bash", QStringList() << "-c" << "echo 'hello' >> /home/winfried/text.txt;");