user1145581
user1145581

Reputation: 1017

Write command to gnome terminal with QProcess

I am trying to write an application with Qt in Netbeans. I am able to open the gnome terminal (in Ubuntu), however I can't seem to get a command to be executed in the terminal once it is open, e.g. to execute the 'ls' command.

Can anyone perhaps help me with some code to execute the ls command in the gnome terminal once it is opened? I am opening the terminal with the following code:

QProcess *proc = new QProcess(this);
proc->start("gnome-terminal");
if (!proc->waitForStarted()) {

}  

Upvotes: 0

Views: 1625

Answers (1)

svlasov
svlasov

Reputation: 10456

Use -e argument:

proc->start("gnome-terminal -e 'ls'");

To keep the window open, go to Edit > Profile Preferences > Command > When command exits and change to Hold the terminal open.

Upvotes: 1

Related Questions