-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.9.1
-
None
-
openSUSE Tumbleweed with KDE Plasma
When QDesktopServices::openUrl is called from &QAction::triggered signal, it fails to activate launched app (e.g. file manager).
Example:
#include <QApplication> #include <QDebug> #include <QDesktopServices> #include <QDir> #include <QMenu> #include <QTimer> #include <QUrl> namespace { void openUrl() { qInfo() << "applicationState:" << qApp->applicationState(); qInfo() << "focusWindow:" << qApp->focusWindow(); QDesktopServices::openUrl(QUrl::fromLocalFile(QDir::rootPath())); } } // namespace int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget window{}; window.resize(640, 480); window.setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(&window, &QWidget::customContextMenuRequested, &window, [&](QPoint pos) { const auto menu = new QMenu(&window); menu->setAttribute(Qt::WA_DeleteOnClose); const auto action = menu->addAction("Do it"); QObject::connect(action, &QAction::triggered, action, [] { openUrl(); // QTimer::singleShot(100, &openUrl); }); menu->popup(window.mapToGlobal(pos)); }); window.show(); return a.exec(); }
1. Launch this app
2. Right click on the window and click on menu item
File manager is launched, but, if it was already opened, its window is not activated.
If openUrl is called with delay (e.g. 100 ms) then activation works.
It seems that following check fails:
https://github.com/qt/qtbase/blob/e1ecc3ae11e01f6a6601b921efb588e13b8baf3b/src/gui/platform/unix/qdesktopunixservices.cpp#L445
QGuiApplication::focusWindow returns nullptr in that moment, despite the fact that application is active (and QGuiApplication::applicationState returns ApplicationActive)