summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2022-10-17 15:19:51 +0200
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2022-10-19 00:10:09 +0200
commitf50f6a456aca6f0782eab2bf475d4f9c86a21f4c (patch)
tree66d9f0aafcfdf67821f08366f2801c4010192d3c /src/plugins/platforms/ios
parentbb1f616ff19586225cd712195ca78bfc64944103 (diff)
QIOSMessageDialog::exec - work around 'windowsless' exec
While the need for such scenario is arguable, we can imagine that some app first shows some message box (by calling QDialog::exec()), and then creates and shows the main UI/window/widget. Without such a widget, app's keyWindow is nil, its rootViewController is also nil and no alert is presented at all. To save the situation, we try hard and check the primary screen's uiWindow (using QIOSScreen::uiWindow) searching for any window and using its root view controller. Pick-to: 6.4 6.2 5.15 Fixes: QTBUG-79977 Change-Id: I9bf38bdf540f1f1dbe42b86df94d6a1b4694e9f2 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qiosmessagedialog.mm20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/plugins/platforms/ios/qiosmessagedialog.mm b/src/plugins/platforms/ios/qiosmessagedialog.mm
index fd14e699e0..1ac1bd0b97 100644
--- a/src/plugins/platforms/ios/qiosmessagedialog.mm
+++ b/src/plugins/platforms/ios/qiosmessagedialog.mm
@@ -11,6 +11,7 @@
#include "qiosglobal.h"
#include "quiview.h"
+#include "qiosscreen.h"
#include "qiosmessagedialog.h"
using namespace Qt::StringLiterals;
@@ -113,6 +114,25 @@ bool QIOSMessageDialog::show(Qt::WindowFlags windowFlags, Qt::WindowModality win
}
UIWindow *window = parent ? reinterpret_cast<UIView *>(parent->winId()).window : qt_apple_sharedApplication().keyWindow;
+ 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)
+ return false;
+
[window.rootViewController presentViewController:m_alertController animated:YES completion:nil];
return true;
}