QProcess: start a compiled c program and output to textBrowser in Linux
-
Hi, welcome to the forum. Check the ProcessError to get a hint on what went wrong. Also, add a call to waitForStarted and see if it hangs. Judging by the pathname, your
a.out
is owned by the userroot
. I assume you're not logged in as root so you probably don't have the sufficient access rights to run that executable. -
Hi
Besides what @Wieland suggests
did you try open a shell and just type
/root/Desktop/a.outand see if it can run ?
in some cases it wants
chmod +x a.outto even be allowed to run.
(normally the compiler / linker does that for you) -
@Naim , @mrjj
If you like trivia (you probably don't...), you can actually execute it without the execute bit set via the accepted answer to https://superuser.com/questions/341439/can-i-execute-a-linux-binary-without-the-execute-permission-bit-being-set :) -
@mrjj said in QProcess: start a compiled c program and output to textBrowser in Linux:
@JNBarchan
But does it set the bit ?
chmod a-x /tmp/lschmod a-x /tmp/ls
clears the executable bit ;) -
I may have find the problem here. My C program a.out runs indefinitely and textBrowser only shows the output once my program have finished executing. I've tried to run another C program that accepts command line input to loop how many times. Its output shows up in textBrowser after it has done looping.
-
@Naim Use http://doc.qt.io/qt-5/qprocess.html#readyReadStandardOutput and http://doc.qt.io/qt-5/qprocess.html#readyReadStandardError to get notifications each time the process writes something to stdout or stderr and read it using http://doc.qt.io/qt-5/qprocess.html#readAllStandardOutput and http://doc.qt.io/qt-5/qprocess.html#readAllStandardError. Do not call waitForFinished, just make sure your proc does not go out of scope (make it class member).