Reputation: 937
I'm using Ubuntu and Qt Creator 4
I have a .cpp program in the executable form (say abc.out
) that I wish to run when I press a button. It contains a number of cin and cout, so I want it to run on a "terminal" (on Ubuntu) so that I am able to input and output values to it. How can I do that?
I've tried system() and also, QProcess p1; p1.start(./abc.out);
Using QProcess, my executable runs but stops at the first cout. It runs on the application output screen in Qt Creator and not on terminal.
For example: I see on application output:
enter name:
When I type the value and press enter here, it doesn't accept the value, but moves to the next line and allows me to type further.
I want to run this abc.out
file on the terminal. Any ideas would be really helpful.
Upvotes: 0
Views: 911
Reputation: 98425
The only sensible solution is to launch the target application in a terminal. Whether your own code provides the terminal window or you reuse an existing terminal application is up to you.
Upvotes: 0
Reputation: 3456
Do you mean Qt Creator 2.4? In any case, on the Projects tab, you should find the Run settings section and from there you can find a "Run in terminal" checkbox. You could also use a Custom Executable option and type there: gnome-terminal --command ./abc.out
The exact details can vary a bit as I'm using Qt Creator 2.5.
This should work when launching from Qt Creator, but when you use your app outside the IDE, you need to launch it from terminal and not by double clicking the executable. To fix this, I can think of two ways:
QProcess::execute("gnome-terminal --command ./abc.out");
), though the problem is different systems have different terminal names.myqprocess.write(input_asked_from_user_by_QtGui);
). Here you probably need to know what information to ask the user beforehand. If you want to display the cout output of the started process, you can use the read
method and friends of the QProcess.Upvotes: 1
Reputation: 1325
From your question I assume that you are writing an application that launches other applications using QProcess. Thats fine, but if your subprocess is waiting for data from the standard input it will wait forever since you did not provide any data. The stdin of your parent application cannot be automatically guided to the subprocess. Imagine you are starting two processes from your main app. To which child process should the input go?
If you want to communicate with child processes, you must use the QIODevice methods of QProcess and send/read data from/to that application.
Upvotes: 0