Solved Stragne behavior with QProcess
-
hi folks.
I am coding and working on MacOS X. This is important to know.
In my main.app I want to launch two different external applications.
Both are also written in QT. Let us call them first.app and second.appThe code I am using for that task is:
QString cmd = "/usr/bin/open"; QStringList arguments; arguments << "-a" << "path-toapplication"; mcProcess = new QProcess(this); mcProcess->start(cmd, arguments); qDebug() << mcProcess->program() << " " << mcProcess->arguments();
-
The first app launches (process is running).
But it takes very long and the window only appears, when I move (shake) the main window from the main app. -
The second.app and the main.app crashes direct after the process has started.
Note: I have tested the launch command "/usr/bin/open -a /path-to-application" from Mac OS X terminal.
In both cases the command is successful and both apps appear very fast and do not crash.Any ideas?
-
-
@ademmler said in Stagne behavior with QProcess:
The first app launches (process is running).
But it takes very long and the window only appears, when I move (shake) the main window from the main app.This sounds like your code is not returning to the event loop. We cannot see any of that in the snippet you posted.
The second app crashes direct after the process has started.
QProcess::error() returns what?
QProcess:: exitCode() returns what?
QProcess::state() ?
Anything useful in the result of QProcess::readAllStandardOutput() or QProcess::readAllStandardError()?Do you even need the /usr/bin/open command? You are not passing a file name to open with the specified application which seems to be the purpose of "open".
-
@ademmler said in Stagne behavior with QProcess:
The first app launches (process is running).
But it takes very long and the window only appears, when I move (shake) the main window from the main app.This sounds like your code is not returning to the event loop. We cannot see any of that in the snippet you posted.
The second app crashes direct after the process has started.
QProcess::error() returns what?
QProcess:: exitCode() returns what?
QProcess::state() ?
Anything useful in the result of QProcess::readAllStandardOutput() or QProcess::readAllStandardError()?Do you even need the /usr/bin/open command? You are not passing a file name to open with the specified application which seems to be the purpose of "open".
-
@ChrisW67 Hi Chris thx for your response.
I have to correct my words:
The second.app and the main.app crashes direct after the process has started.I will added your response codes and "magic" now the app does not crash any longer.
But I have to say - by some other reasons" I upgraded to Qt from 5.12 to 5.15.
Hence I can't say if this solved the issue ....There is no file to be open. But it is the official way to launch an app on Mac OSX.
If you just call the app path you get:/Applications/second.app -bash: /Applications/second.app: is a directory
And if you call /Applications/second.app/Contents/MacOS/executable you have a terminal window popping up.
Thx for helping me ...
-
@ChrisW67 Me again.
In case of the first app I get an unknown error:
QString cmd = "/usr/bin/open"; QStringList arguments; arguments << "-a" << "/Applications/ColorNavigator 7.app"; mcProcess = new QProcess(this); mcProcess->start(cmd, arguments); qDebug() << mcProcess->program() << " " << mcProcess->arguments(); qDebug() << mcProcess->error(); qDebug() << mcProcess->exitCode(); qDebug() << mcProcess->state(); }
The response:
QProcess::Starting "/usr/bin/open" ("-a", "/Applications/ColorNavigator 7.app") QProcess::UnknownError 0 QProcess::Starting
An unknown error can be everything. Is there some option to bring this process to the foreground?
-
@ademmler Can you try with a path without spaces?
-
The first.app has no space. Also I tried the second without:
"/usr/bin/open" ("-a", "/Applications/ColorNavigator7.app") Process error: QProcess::UnknownError Process exit code: 0 Process state: QProcess::Starting
As you see the same state and error. But now Colornavigator crashed ;-)
Hence the developer of Colornavigator have used a hardcoded path somehow ... -
@ademmler, currently the process has not had time to start before your debug output. Just for diagnostic purposes try explicitly waiting for the process to start and finish:
bool success = mcProcess->waitForStarted(5000); qDebug() << mcProcess->program() << " " << mcProcess->arguments() << "started" << success ; success = mcProcess->waitForFinished(5000); qDebug() << mcProcess->program() << " " << mcProcess->arguments() << "finished" << success; qDebug() << mcProcess->error(); qDebug() << mcProcess->exitCode(); qDebug() << mcProcess->state();
or you could connect the QProcess objects to slots to handle errorOccurred(), finished(), etc.
-
@ChrisW67 thx for your help. I tested your hint,
After a long while the second.app appears. Regardless what QtProcess is responding."/usr/bin/open" ("-a", "/Applications/ColorNavigator 7.app") started false "/usr/bin/open" ("-a", "/Applications/ColorNavigator 7.app") finished false Process error: QProcess::Timedout Process exit code: 0 Process state: QProcess::Running
Looks like that this app is simple very slow at launch ...