Launching the application in the foreground with Qt under MacOS X

I have problems with the small Qt 5.0.1 program on Mac OS X 10.8. (I have not tested other platforms yet.)

I am running an external Mac OS X program with this line of code:

QDesktopServices::openUrl(QUrl::fromLocalFile(fullpath)); 

Where fullpath contains the application path like:

 /Users/schube/QTWorkspace/HelloWorld-build-Desktop_Qt_5_0_1_clang_64bit-Debug/HelloWorld.app/Contents/MacOS/../../../Aptus.app 

( Aptus.app is a random application that I chose, it can be any application. I put it in this way for testing purposes).

The application starts correctly, but always in the background; or at least outside the Finder window. Really weird!

How to make a new running application go to the fore?

+2
source share
2 answers

Use QProcess instead, but make sure that instead of using the path to the executable as an object to run, pass it to the open command as an argument. Something like that: -

 QString cmd = QString("open %1").arg(fullpath); // may need QUrl::fromLocalFile(fullpath) QProcess::startDetached(cmd); 

Without using "open", it will also open to other applications.

Note that you can also use the execute function if you want to wait for the program to finish.

In addition, with the open command, it seems to me that you need to pass the path to the set of applications, and not the full path to its executable file in Content / MacOS. Or it should work.

+2
source

This may be a feature of the Mac OSX window manager so that it does not steal focus.

You may need to modify your application to minimize it.

0
source

Source: https://habr.com/ru/post/1207148/


All Articles