Fix crash due to use of native widgets on Windows

Qt has corner cases when all of its widgets are native widgets.
This particular crash was a loop between QWidget::create()
and QWidget::createWinId().
This commit is contained in:
Sergio Martins
2022-02-02 13:15:43 +00:00
parent 481dae64c3
commit b13ba1e42e

View File

@@ -788,6 +788,12 @@ static QWidgetOrQuick *qtTopLevelForHWND(HWND hwnd)
// Case not supported for QtQuick.
const QWidgetList widgets = qApp->topLevelWidgets();
for (QWidget *widget : widgets) {
if (!widget->windowHandle()) {
// Don't call winId on windows that don't have it, as that will force all its childrens to have it,
// and that's not very stable. a top level might not have one because it's being destroyed, or because
// it's a top-level just because it has't been reparented I guess.
continue;
}
if (hwnd == ( HWND )widget->winId()) {
return widget;
}