即使弹出其他进程,我也试图强制我的应用程序保持领先地位。这是我的简化版本main:
主文件
QApplication app{argc, argv};
QQmlApplicationEngine engine;
engine.load(QUrl{"qrc:/file.qml"});
return app.exec();
我需要一个解决方案Windows和Linux。但是优先级是前者,似乎没有Qt解决方案。这是我尝试过的:
#ifdef _WIN32
HWND hCurWnd = ::GetForegroundWindow();
DWORD dwMyID = ::GetCurrentThreadId();
DWORD dwCurID = ::GetWindowThreadProcessId(hCurWnd, NULL);
::AttachThreadInput(dwCurID, dwMyID, TRUE);
::SetWindowPos(hCurWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
::SetWindowPos(hCurWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
bool ok = ::SetForegroundWindow(hCurWnd);
LOG_INFO() << ok;
::AttachThreadInput(dwCurID, dwMyID, FALSE);
::SetFocus(hCurWnd);
::SetActiveWindow(hCurWnd);
#endif
ok返回true,但它似乎不起作用。外部进程在启动后仍然出现在应用程序的顶部。
加载的QML文件visibility设置为FullScreen. 它的类型是ApplicationWindow.