QProcess pro;
pro.start("Notepad");
QTimer::singleShot(3000, &pro, &QProcess::terminate);
After 3 seconds it must terminate my notepad.exe but it won't I have no idea what's the problem
I changed it with (kill) but it still won't work
QProcess pro;
pro.start("Notepad");
QTimer::singleShot(3000, &pro, &QProcess::terminate);
After 3 seconds it must terminate my notepad.exe but it won't I have no idea what's the problem
I changed it with (kill) but it still won't work
By design (OS-dependant) running a command without full path is an equivalent of
systemfunction in POSIX and, by its implementation it doesn't have this granularity of control on created processes, because there was a shell process between your application and one you meant to execute. Asnotepad.exeis a GUI application, it immediately returns control to shell, which is terminated afterward, a Windows-specific behaviour of program's stub code. For all purposes yourQProcessis already stopped.Qt had in past special behaviour for Windows, where command are passed to
cmd.exe. The rules regarding to running, passing arguments to and terminating processes change from program to program, most notable would becmd.exeitself. Behaviour still vary with newfangledstartCommandmember function.You have to either find the true location of notepad.exe, e.g. via
QStandardPaths::locate(introduced in Qt 5.0) or ask user to configure it.