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. QProcess Unable to Open Specific GUI Application
Forum Updated to NodeBB v4.3 + New Features

QProcess Unable to Open Specific GUI Application

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 2.7k Views 1 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.
  • S Offline
    S Offline
    sundarraman
    wrote on last edited by
    #1

    I'm trying to launch a GUI Application from a QProcess. I've set all required env variables before I start the QProcess. I'm using Qt 5.3.1 on Linux. Here is my code:

    @QProcess *proc = new QProcess();
    QStringList env = proc->systemEnvironment();
    env.append("MY_ENV=/home/sundar/path/"); // My own env settings for the process
    proc->setEnvironment(env);
    proc->start("/home/sundar/myapp");
    qDebug() << "The process Id is : " << proc->processId();
    proc->waitForFinished();
    qDebug() << "The Exit Status is " << proc->exitStatus();@

    The GUI of the application I'm trying to launch does not show up at all. It hangs for some 20 seconds and the QProcess exits with a Code "0". I tried to do a "ps command" on the process id on a separate terminal before the process comes out and this is the output:

    ps <ps_id_from_above>:
    PID TTY STAT TIME COMMAND
    37890 pts/8 S 0.00 /home/sundar/myapp --sim

    So the process seems to be started but for some reason the GUI does not show up. Any ideas of what could be wrong here. Thanks!!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      It is recommended to use processEnvironment() and setProcessEnvironment() instead of setEnvironment().

      Try launching the process detached (startDetached()).

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sundarraman
        wrote on last edited by
        #3

        @sierdzio Thanks for your reply.

        I tried with setProcessEnvironment but still I don't see any difference.

        When I use "proc->startDetached("myapp");" the process does not seem to start at all and my program completes immediately. I checked from a terminal using "ps -aux | grep myapp" and I don't see any process getting launched.

        I also tried "proc->execute("myapp");". In this case, the QProcess hangs forever and does not seem to complete. From terminal, I'm able to see a process getting initiated but however no GUI is getting launched. Any ideas?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi and welcome to devnet,

          What application are you trying to start ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alex_malyu
            wrote on last edited by
            #5

            Might be a stupid question , but can you start it from the command line?
            What is the difference between your environment (when you are able to start it ) and you are trying to set?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sundarraman
              wrote on last edited by
              #6

              I'm trying to start a system verilog simulator. (named QuestaSim)

              Yes I'm able to start the application from the command line and I've set all required env variables that are needed by the application (PATH, LD_LIBRARY_PATH etc). So there is no difference in environment.

              Also when I try to launch my application in batch mode (i.e "myapp -c run -all") with QProcess, the application runs. But I'm unable to launch the application in GUI mode.

              @proc->start("myapp -c run -all"); // This works since I'm starting myapp in batch mode@

              However
              @proc->start("myapp"); // This does not work. This should open the application GUI and wait for my input@

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sundarraman
                wrote on last edited by
                #7

                Ok I finally found the problem myself. There are two things which I did to get things working.

                First, I was using qt version 5.3.1 in linux and I had to upgrade to qt version 5.4.1.

                However just upgrading alone does not fix the issue. I needed to use "startDetached" function as suggested, but however in-order to get my external application launched in GUI mode, I had to enable the option "Run in Terminal" in the Projects->Run settings. Once this option is enabled, when the qt application is launched, qt creator process stub appears and then the application opens. I do not know what is the reason but this seems to the required in-order to open my external app using QProcess with startDetached() function. Hope this helps someone.

                1 Reply Last reply
                0

                • Login

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