QProcess Unable to Open Specific GUI Application
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
qDebug() << "The process Id is : " << proc->processId();
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:
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!!
It is recommended to use processEnvironment() and setProcessEnvironment() instead of setEnvironment().
Try launching the process detached (startDetached()).
@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?
Hi and welcome to devnet,
What application are you trying to start ?
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?
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@
@proc->start("myapp"); // This does not work. This should open the application GUI and wait for my input@
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.