iOS: Support message box at startup without relying on screen's window
Task-number: QTBUG-121781 Change-Id: Iafc911dad6c668799383f423e38ab389c29688b4 Reviewed-by: Doris Verria <doris.verria@qt.io>
This commit is contained in:
parent
e48a9aca5d
commit
eb9923c67e
@ -88,10 +88,15 @@ int infoPlistValue(NSString* key, int defaultValue)
|
|||||||
UIWindow *presentationWindow(QWindow *window)
|
UIWindow *presentationWindow(QWindow *window)
|
||||||
{
|
{
|
||||||
UIWindow *uiWindow = window ? reinterpret_cast<UIView *>(window->winId()).window : nullptr;
|
UIWindow *uiWindow = window ? reinterpret_cast<UIView *>(window->winId()).window : nullptr;
|
||||||
#if !defined(Q_OS_VISIONOS)
|
if (!uiWindow) {
|
||||||
if (!uiWindow)
|
auto *scenes = [qt_apple_sharedApplication().connectedScenes allObjects];
|
||||||
uiWindow = qt_apple_sharedApplication().keyWindow;
|
if (scenes.count > 0) {
|
||||||
#endif
|
auto *windowScene = static_cast<UIWindowScene*>(scenes[0]);
|
||||||
|
uiWindow = windowScene.keyWindow;
|
||||||
|
if (!uiWindow && windowScene.windows.count)
|
||||||
|
uiWindow = windowScene.windows[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
return uiWindow;
|
return uiWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,25 +117,17 @@ bool QIOSMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality win
|
|||||||
}
|
}
|
||||||
|
|
||||||
UIWindow *window = presentationWindow(parent);
|
UIWindow *window = presentationWindow(parent);
|
||||||
if (!window) {
|
|
||||||
qCDebug(lcQpaWindow, "Attempting to exec a dialog without any window/widget visible.");
|
|
||||||
|
|
||||||
auto *primaryScreen = static_cast<QIOSScreen*>(QGuiApplication::primaryScreen()->handle());
|
|
||||||
Q_ASSERT(primaryScreen);
|
|
||||||
|
|
||||||
window = primaryScreen->uiWindow();
|
|
||||||
if (window.hidden) {
|
|
||||||
// With a window hidden, an attempt to present view controller
|
|
||||||
// below fails with a warning, that a view "is not a part of
|
|
||||||
// any view hierarchy". The UIWindow is initially hidden,
|
|
||||||
// as unhiding it is what hides the splash screen.
|
|
||||||
window.hidden = NO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!window)
|
if (!window)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (window.hidden) {
|
||||||
|
// With a window hidden, an attempt to present view controller
|
||||||
|
// below fails with a warning, that a view "is not a part of
|
||||||
|
// any view hierarchy". The UIWindow is initially hidden,
|
||||||
|
// as unhiding it is what hides the splash screen.
|
||||||
|
window.hidden = NO;
|
||||||
|
}
|
||||||
|
|
||||||
[window.rootViewController presentViewController:m_alertController animated:YES completion:nil];
|
[window.rootViewController presentViewController:m_alertController animated:YES completion:nil];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user