QProcess with CreateNoWindow

335 Views Asked by At

In C# there is an attribute which enables application to run 3rd party apps without showing the app window.

Is there any way to run a console application without showing the console window in QT without using Win32 CreateProcess function?

1

There are 1 best solutions below

2
On

QProcess.start() will run the console application without showing its window, but you may also wish to have some control over it. Please see this example:

QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
p.setStandardOutputFile("out.txt");
p.start("cmd.exe", QStringList()<<"/C"<<"ping"<<"127.0.0.1");
p.waitForStarted();
p.waitForFinished();

You can pass commands and parameters to the console using second argument in the start method (inside QStringList). It is also possible to redirect the output to some file, with setStandardOutputFile method.

If you need to show the window, use p.startDetached().