From da3a600824fa2f809fe2cdb317d528007c40eb43 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 30 Oct 2017 14:21:07 +0100 Subject: [PATCH] QWindowsXPStyle: Speed up level window loop in helper winId() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rewrite the loop using QGuiApplication::allWindows() to avoid the creation of temporary containers by QApplication::topLevelWidgets() and expensive checks. Task-number: QTBUG-64072 Change-Id: I56ef29b12f7bcbe274f3e00a6007d75d33f22b10 Reviewed-by: Oliver Wolff Reviewed-by: MÃ¥rten Nordheim --- src/plugins/styles/windowsvista/qwindowsxpstyle.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index 1f7e223fe2..cf344c8f88 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -400,11 +400,10 @@ HWND QWindowsXPStylePrivate::winId(const QWidget *widget) return hwnd; // Find top level with native window (there might be dialogs that do not have one). - const auto topLevels = QApplication::topLevelWidgets(); - for (const QWidget *toplevel : topLevels) { - if (toplevel->windowHandle() && toplevel->windowHandle()->handle()) - if (const HWND topLevelHwnd = QApplicationPrivate::getHWNDForWidget(toplevel)) - return topLevelHwnd; + const auto allWindows = QGuiApplication::allWindows(); + for (const QWindow *window : allWindows) { + if (window->isTopLevel() && window->type() != Qt::Desktop && window->handle() != nullptr) + return reinterpret_cast(window->winId()); } return GetDesktopWindow();