Important: Please read the Qt Code of Conduct -

Calling executable using QProcess

  • Dear Qt community!

    Cheers! I am trying to call a Linux executable from Qt GUI. The simple GUI button has "Open File Name" button. Once button clicked - the executable launch from Terminal. i.e open the Gnome Terminal first , execute the file in given path. i.e equivalent to ./testfile I am using Ubuntu.

      QProcess *process=new QProcess(new QProcess());
       // QProcess *process=new QProcess(this);
       QString program = "/home/Desktop/Testfile";
        process->start(program, QStringList() << " ");
       // process->start("cd /home/yogin/&& Testfile");
        //checking the process start
        qDebug()<<"Process started";
     /*Success message*/
        QMessageBox::information(this,"Alert"," Calling Executable  success!");

    Now, the program runs without error but the executable not launching. Please note,

    1. enabled the "Run in Terminal option on Qt Run setting.
    2. added the export PATH="$PATH:." ,so the file will run without ./ on Terminal.

    Attached screen shots (Reverse order) Not sure why getting "Child process exited with status 0"
    Any ideas/tips highly useful. Thanks a lot !
    3_1533658071307_Screenshot from 2018-08-07 16-07-11.png 2_1533658071307_Screenshot from 2018-08-07 16-07-04.png 1_1533658071306_Screenshot from 2018-08-07 16-06-57.png 0_1533658071306_Screenshot from 2018-08-07 16-06-34.png

    With kind regards,

  • @Chandras002

    QString program = "/home/Desktop/Testfile";
        process->start(program, QStringList() << " ");

    Why do you pass a single argument of a space character to your program?

    Is your /home/Desktop/Testfile an executable file? If it isn't, nothing is going to run....

    ... And you do not check for errors (you just assume it is running), wait for it to complete, or anything.

    The only reason you're seeing the Terminal window at all is because of your

    1.enabled the "Run in Terminal option on Qt Run setting.

    Outside of Qt Creator that would not be shown.

    My guess is that you're seeing nothing because you're not actually succeeding in executing anything, and doubtless there will be an error there (which you're not seeing) to that effect.

  • Lifetime Qt Champion

    Besides @JonB s good points im wondering
    what testfile is ?
    Did you compiled the program yourself or
    where did u get it?

  • Sorry for late reply.

    The testfile is executable which involves calling some processor related info using Intel API's . even with out using Qt, I am believe this executable not have an option "Open with Command Shell" on Ubuntu. So, think it is not Qt issue. Any tips, how to make the Linux executable(testfile) with Open with application command shell by default. I trying to achieve this before use Qt to run the testfile .

  • Lifetime Qt Champion

    @Chandras002 said in Calling executable using QProcess:

    Any tips, how to make the Linux executable

    chmod u+x /home/Desktop/Testfile

    Also, did you remove that empty parameter

    QString program = "/home/Desktop/Testfile";
    process->start(program, QStringList() << " "); // Why this " "?!

    Connect a slot to and print the error in the slot.

  • Lifetime Qt Champion


    QProcess *process=new QProcess(new QProcess());

    looks strange. why not QProcess *process=new QProcess(this); or just QProcess *process=new QProcess;?

Log in to reply