FarFarAway
FarFarAway

Reputation: 1115

starting another program with arguments from qt app

I have a simple app

int main(int argc, char* argv[]){
//cout << argv[1];
cout << "hello world";
getchar();
}

and I want to start it from qt program using

QProcess *process= new QProcess(this);
QString appPath= "..../.../TestApp2.exe";
process->start(appPath);

the problem is that my program dosen't starts, even without arguments. I have tried to start a standard app like "calc" and it worked. How could I start my app with specific args (sure after uncommitting the second line of the first snippet)

Upvotes: 0

Views: 478

Answers (1)

Mike
Mike

Reputation: 8355

I have tried to start a standard app like "calc" and it worked. How could I start my app

Your application is a console application.

QProcess hides the console window for console applications and redirects their STDOUT/STDERR for you to read them (using readAllStandardOutput(), readAllStandardError(), ...). and whatever you write() to your QProcess goes to its STDIN. So, if you are expecting to see a console window when the process starts, you are wrong.

If you want to start a console application without hiding its console window, you can use QProcess::startDetached():

QProcess::startDetached("test.exe");

But most of the times there is no reason to do so. QProcess is meant to be used from a GUI application in order to start a process behind the scenes, and take a result from it. After that, you can display the result to the user the way you like. A user of a GUI application usually doesn't expect a console window asking him/her for input every now and then. Also, He/She wouldn't expect to see the result in a console window.

Upvotes: 1

Related Questions