I am running a Qt application that starts a process (Qt Assistant)
The process window is displayed outside the caller’s window when the application is running on OSX ...
How can I bring him ahead?
Code from Qt documentation:
QProcess *process = new QProcess(); QStringList args; args << QLatin1String("-collectionFile") << QLatin1String("mycollection.qhc");

Note on using "-enableRemoteControl" - see question
Marked as duplicate / vote for closed indicates an example that starts the process as a separate one. Trying this did not solve the problem - also, help should be a child process for the application.
Update based on comments / replies:
Attempt
QString app = "path/to/Assistant"; // since I use the copy from inside bundle QString helpfile = "path/to/helpfile"; QString cmd = QString("open -a '%1' --args '-collectionFile' '%2'").arg(app).arg(helpFile); qDebug()<<cmd; m_helpProcess->start(cmd); m_helpProcess->waitForStarted(); if (m_helpProcess->state() == QProcess::Running) qDebug()<<"help started"; else qDebug()<<m_helpProcess->errorString();
Result:
help started (but the window doesn't show at all, I think it gives an error and closes)
(If I copy the path from cmd to Terminal , it works fine, so the arguments seem to be correct ...)
Update after trying to play using osascript:
After the code above, to start the Assistant, I added (one of many versions of ActivScript)
Q_PID pid = m_helpProcess->pid(); QString activateScript = "tell application System Events to perform action \"AXRaise\" of application " + app + "\n"; QString activateScript = "tell application System Events to perform action \"AXRaise\" of window with title \"My App Help\"\n"; QString activateScript = "tell application " + app + " to activate\n"; QString activateScript = "tell application Assistant activate\n"; QString activateScript = QString("tell application \"System Events\" \n") + QString("set (frontmost of processes whose id is ") + QString::number(pid) + QString(") to true\n") + QString("end tell\n"); QString activateScript = QString("tell application \"System Events\" \n") + QString("tell process whose id is ") + QString::number(pid) + QString(") to activate\n") + QString("end tell\n") + QString("end tell\n"); QString activateScript = QString("tell application \"System Events\" to perform action \"AXRaise\"") + QString("of application whose id is ") + QString::number(pid) + QString("end tell\n"); QString activateScript = QString("tell process whose id is ") + QString::number(pid) + QString(") to activate\n") + QString("end tell\n"); QString osaScript = "/usr/bin/osascript"; QStringList osaArguments; osaArguments << "-l" << "AppleScript"; QProcess p; p.start(osaScript, osaArguments); p.write(activateScript.toUtf8()); p.closeWriteChannel(); p.waitForStarted(-1);
None of the above script versions had any effect.
(The possibility of scripts that use pid to ignore me is that osascript can use a window identifier that may be different from the process identifier - I was looking for ways to get the window identifier, but did not find anything that I could use from inside Qt.)
Additional update:
I created a signal and sent "emit" to the caller after the start so that maybe I could do something to hide the caller’s window. Trying to minimize and then restore the caller looked horrible, especially because of the animation. But that would be better than nothing ... At least he can notify the user that something has happened, and if the calling user is maximized and the docking station is hidden to show the caller that there might be help in background ... Something, (this is not really a solution)
Well, even this terrible attempt does not work. If the help is already running, then minimizing and restoring the caller’s window will cause the help window to be visible for a moment, and, of course, the restored caller will be displayed above it. But ... If the assistant starts for the first time, there is NOTHING in the back !!! waitForStarted () is already true, but the helper takes much longer to show .... Is the help database probably loading too long?
Could this be the reason that the process always starts in the background (not a background process, but like a window outside the caller’s window)? He does not show himself fast enough so as not to get focus? And if something like this happens, how can I fix it?
...... I tried to add a timer, and then called the above actionscript commands, I could clearly see the wait cursor when the Assistant window appeared outside the application window, but did not observe the effect when the ActionScript elements were executed - so they should all be wrong.
This is incredibly frustrating!
There seems to be a solution on Windows for this problem (pairing the pair with ideas):
(1) Bring a front window application managed with QProcess
(2) qt-assistant-how-to-maximize-help-window-when-qt-assistent-is-start-as-proces
But I did not see this strange behavior in Linux or Windows. This only looks like OSX for my application. Since the behavior of the process depends on the system, I need some solution for OSX ... Please help!