简体   繁体   English

如何在OSX中执行时强制Qt应用程序成为活动/前台窗口?

[英]How to force a Qt Application to be the active/foreground window upon execution in OSX?

I'm going through Qt tutorials on OSX. 我正在通过OSX上的Qt教程。 One thing I noticed is that when I launch the executable (eg the push button hello world example), the app will launch as a background window and I have to switch tasks to bring it into the foreground. 我注意到的一件事是,当我启动可执行文件(例如按钮hello world示例)时,应用程序将作为后台窗口启动,我必须切换任务以将其置于前台。 How can I force the Qt application window to be the foreground window upon execution? 如何在执行时强制Qt应用程序窗口成为前台窗口?

I'd like to do this since it's how most apps behave, not to mention that manually switching tasks slows down my edit-compile-run-debug cycle). 我想这样做,因为它是大多数应用程序的行为,更不用说手动切换任务会减慢我的编辑 - 编译 - 运行 - 调试周期)。

The behavior you observe is due to interaction with the debugger when you start the application under the debugger using ⌘-Y. 您观察到的行为是由于在使用⌘-Y在调试器下启动应用程序时与调试器的交互。 If you simply run it using ⌘-R, it behaves as you expect. 如果您只是使用⌘-R运行它,它的行为与您期望的一样。 Your application itself is fine. 你的申请本身没问题。

Starting OS X applications by directly firing up the executable from within the app bundle from the terminal will act similarly to running them using ⌘-Y -- they all start in the background. 通过从终端直接启动应用程序包中的可执行文件来启动OS X应用程序将类似于使用⌘-Y运行它们 - 它们都在后台启动。 Qt is probably mimicking whatever magic Finder does when it starts the process via ⌘-R -- said magic may reduce to simply bringing the child app to the foreground. Qt可能模仿Finder在通过⌘-R启动过程时所做的一切 - 所说的魔法可能会减少到简单地将子应用程序带到前台。 gdb on OS X is not so "clever", and probably for a good reason. OS X上的gdb并不那么“聪明”,可能是有充分理由的。

OS X approach is to try harder not to steal focus -- a good thing IMHO. OS X的做法是更加努力,不要窃取焦点 - 恕我直言。

If you merely want to run the application, not debug it, then modify your launch command to look like open -a '/Users/daj/foo/bar/baz.app' , where baz.app is the app bundle folder. 如果您只想运行应用程序,而不是调试它,那么将您的启动命令修改为open -a '/Users/daj/foo/bar/baz.app' daj/foo/bar/baz.app open -a '/Users/daj/foo/bar/baz.app' ,其中baz.app是应用程序包文件夹。 Do not append a trailing slash. 不要附加尾部斜杠。

If you can coax your debugger to follow through to child processes, then you can of course launch open itself under gdb, and it will work as expected -- with your child application on top. 如果您可以哄骗调试器来跟进子进程,那么您当然可以在gdb下启动它自己,并且它将按预期工作 - 将您的子应用程序放在最前面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM