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.
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.outThe 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 thereadmethod and friends of the QProcess.