mercredi 1 juillet 2015

Running external executable in Qt using QProcess

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!

Aucun commentaire:

Enregistrer un commentaire