Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Calling executable using QProcess
Forum Updated to NodeBB v4.3 + New Features

Calling executable using QProcess

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chandras002
    wrote on 7 Aug 2018, 16:13 last edited by
    #1

    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,
    chandra

    J A 2 Replies Last reply 7 Aug 2018, 16:24
    0
    • C Chandras002
      7 Aug 2018, 16:13

      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,
      chandra

      J Offline
      J Offline
      JonB
      wrote on 7 Aug 2018, 16:24 last edited by JonB 8 Jul 2018, 16:27
      #2

      @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.

      1 Reply Last reply
      4
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 7 Aug 2018, 20:28 last edited by
        #3

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

        1 Reply Last reply
        1
        • C Offline
          C Offline
          Chandras002
          wrote on 20 Aug 2018, 03:30 last edited by
          #4

          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 .

          J 1 Reply Last reply 20 Aug 2018, 04:39
          0
          • C Chandras002
            20 Aug 2018, 03:30

            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 .

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 20 Aug 2018, 04:39 last edited by
            #5

            @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 http://doc.qt.io/qt-5/qprocess.html#errorOccurred and print the error in the slot.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • C Chandras002
              7 Aug 2018, 16:13

              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,
              chandra

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 20 Aug 2018, 18:18 last edited by
              #6

              @Chandras002

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

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

              Qt has to stay free or it will die.

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved