I'm trying to run an external executable (code below) in Qt as a separate process.
test.c:
#include <stdio.h>
int main () {
FILE *f;
f = fopen("a.txt", "w");
fprintf(f, "1\n");
fclose(f);
return 1;
}
and in Qt I have:
QProcess* process = new QProcess();
QString program = "/Users/myUser/Desktop/a.out";
process->execute(program);
I've read up on the differences between execute(), start(), and startDetached() and to my understanding I want to use execute() because I want the process running the external executable to finish before continuing execution in the main process. However I've tried all three expecting to find a file a.txt containing the text "1" in it, but it doesn't exist. Any help or suggestions as to why it's not working? Thanks!
QProcess::executeis a static function so you don't have to create a new instance ofQProcess. Just to clarify - do you want the calling program to wait for the process to finish before continuing execution? Are you sure the path to the executable is correct? What directory are you running the parent program from (thea.txtmay be in that directory if it isn't the same asa.out's directory).QDir::current(). I'm pretty sure you haven't looked there for the output file.