aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Eftevaag <oliver.eftevaag@qt.io>2024-02-20 14:43:05 +0100
committerOliver Eftevaag <oliver.eftevaag@qt.io>2024-02-22 16:42:16 +0100
commitf52afa7232ab7cce58e0357149be7d41086b32e7 (patch)
tree3844f9b3e108183de5671aaf203407dd884b6737
parent385a24c1b244e07ddb65c9b8449b8255c7e3231d (diff)
Dialogs: delay calling componentComplete until parent is set
The non-native dialogs are created by QQmlComponent::create(), and the parent is set right after the dialogs are created. This would mean that componentComplete would get called before the parent were set to anything other than nullptr, and the ancestors could not be traversed in order to find the nearest parent item, which is useful for finding the window that the dialog belongs to. Change-Id: I650a27a3d1fa85a204976e7a093b45e804324d45 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r--src/quickdialogs/quickdialogsquickimpl/qquickplatformcolordialog.cpp4
-rw-r--r--src/quickdialogs/quickdialogsquickimpl/qquickplatformfiledialog.cpp4
-rw-r--r--src/quickdialogs/quickdialogsquickimpl/qquickplatformfolderdialog.cpp4
-rw-r--r--src/quickdialogs/quickdialogsquickimpl/qquickplatformfontdialog.cpp4
-rw-r--r--src/quickdialogs/quickdialogsquickimpl/qquickplatformmessagedialog.cpp4
5 files changed, 15 insertions, 5 deletions
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickplatformcolordialog.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickplatformcolordialog.cpp
index 205b4e0b1b..dc520bb021 100644
--- a/src/quickdialogs/quickdialogsquickimpl/qquickplatformcolordialog.cpp
+++ b/src/quickdialogs/quickdialogsquickimpl/qquickplatformcolordialog.cpp
@@ -43,7 +43,7 @@ QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent)
return;
}
- m_dialog = qobject_cast<QQuickColorDialogImpl *>(colorDialogComponent.create());
+ m_dialog = qobject_cast<QQuickColorDialogImpl *>(colorDialogComponent.beginCreate(qmlContext));
if (!m_dialog) {
qmlWarning(parent) << "Failed to create an instance of the non-native ColorDialog:\n"
<< colorDialogComponent.errorString();
@@ -52,6 +52,8 @@ QQuickPlatformColorDialog::QQuickPlatformColorDialog(QObject *parent)
// Give it a parent until it's parented to the window in show().
m_dialog->setParent(this);
+ colorDialogComponent.completeCreate();
+
connect(m_dialog, &QQuickDialog::accepted, this, &QPlatformDialogHelper::accept);
connect(m_dialog, &QQuickDialog::rejected, this, &QPlatformDialogHelper::reject);
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickplatformfiledialog.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickplatformfiledialog.cpp
index 1c9174a8e4..e020e201a1 100644
--- a/src/quickdialogs/quickdialogsquickimpl/qquickplatformfiledialog.cpp
+++ b/src/quickdialogs/quickdialogsquickimpl/qquickplatformfiledialog.cpp
@@ -47,7 +47,7 @@ QQuickPlatformFileDialog::QQuickPlatformFileDialog(QObject *parent)
qmlWarning(parent) << "Failed to load non-native FileDialog implementation:\n" << fileDialogComponent.errorString();
return;
}
- m_dialog = qobject_cast<QQuickFileDialogImpl*>(fileDialogComponent.create());
+ m_dialog = qobject_cast<QQuickFileDialogImpl*>(fileDialogComponent.beginCreate(qmlContext));
if (!m_dialog) {
qmlWarning(parent) << "Failed to create an instance of the non-native FileDialog:\n" << fileDialogComponent.errorString();
return;
@@ -55,6 +55,8 @@ QQuickPlatformFileDialog::QQuickPlatformFileDialog(QObject *parent)
// Give it a parent until it's parented to the window in show().
m_dialog->setParent(this);
+ fileDialogComponent.completeCreate();
+
connect(m_dialog, &QQuickDialog::accepted, this, &QPlatformDialogHelper::accept);
connect(m_dialog, &QQuickDialog::rejected, this, &QPlatformDialogHelper::reject);
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickplatformfolderdialog.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickplatformfolderdialog.cpp
index d0ccea353e..1228d390d8 100644
--- a/src/quickdialogs/quickdialogsquickimpl/qquickplatformfolderdialog.cpp
+++ b/src/quickdialogs/quickdialogsquickimpl/qquickplatformfolderdialog.cpp
@@ -46,7 +46,7 @@ QQuickPlatformFolderDialog::QQuickPlatformFolderDialog(QObject *parent)
qmlWarning(parent) << "Failed to load non-native FolderDialog implementation:\n" << folderDialogComponent.errorString();
return;
}
- m_dialog = qobject_cast<QQuickFolderDialogImpl*>(folderDialogComponent.create());
+ m_dialog = qobject_cast<QQuickFolderDialogImpl*>(folderDialogComponent.beginCreate(qmlContext));
if (!m_dialog) {
qmlWarning(parent) << "Failed to create an instance of the non-native FolderDialog:\n" << folderDialogComponent.errorString();
return;
@@ -54,6 +54,8 @@ QQuickPlatformFolderDialog::QQuickPlatformFolderDialog(QObject *parent)
// Give it a parent until it's parented to the window in show().
m_dialog->setParent(this);
+ folderDialogComponent.completeCreate();
+
connect(m_dialog, &QQuickDialog::accepted, this, &QPlatformDialogHelper::accept);
connect(m_dialog, &QQuickDialog::rejected, this, &QPlatformDialogHelper::reject);
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickplatformfontdialog.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickplatformfontdialog.cpp
index 4ef0b1bec6..5255cf05e8 100644
--- a/src/quickdialogs/quickdialogsquickimpl/qquickplatformfontdialog.cpp
+++ b/src/quickdialogs/quickdialogsquickimpl/qquickplatformfontdialog.cpp
@@ -53,7 +53,7 @@ QQuickPlatformFontDialog::QQuickPlatformFontDialog(QObject *parent)
return;
}
- m_dialog = qobject_cast<QQuickFontDialogImpl *>(fontDialogComponent.create());
+ m_dialog = qobject_cast<QQuickFontDialogImpl *>(fontDialogComponent.beginCreate(qmlContext));
if (!m_dialog) {
qmlWarning(parent) << "Failed to create an instance of the non-native FontDialog:\n"
@@ -63,6 +63,8 @@ QQuickPlatformFontDialog::QQuickPlatformFontDialog(QObject *parent)
m_dialog->setParent(this);
+ fontDialogComponent.completeCreate();
+
connect(m_dialog, &QQuickDialog::accepted, this, &QPlatformDialogHelper::accept);
connect(m_dialog, &QQuickDialog::rejected, this, &QPlatformDialogHelper::reject);
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickplatformmessagedialog.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickplatformmessagedialog.cpp
index a9f1e858ed..fb23b39c86 100644
--- a/src/quickdialogs/quickdialogsquickimpl/qquickplatformmessagedialog.cpp
+++ b/src/quickdialogs/quickdialogsquickimpl/qquickplatformmessagedialog.cpp
@@ -38,7 +38,7 @@ QQuickPlatformMessageDialog::QQuickPlatformMessageDialog(QObject *parent)
return;
}
- m_dialog = qobject_cast<QQuickMessageDialogImpl *>(messageDialogComponent.create());
+ m_dialog = qobject_cast<QQuickMessageDialogImpl *>(messageDialogComponent.beginCreate(qmlContext));
if (!m_dialog) {
qmlWarning(parent) << "Failed to create an instance of the non-native MessageBox:\n"
@@ -48,6 +48,8 @@ QQuickPlatformMessageDialog::QQuickPlatformMessageDialog(QObject *parent)
m_dialog->setParent(this);
+ messageDialogComponent.completeCreate();
+
connect(m_dialog, &QQuickDialog::accepted, this, &QPlatformDialogHelper::accept);
connect(m_dialog, &QQuickDialog::rejected, this, &QPlatformDialogHelper::reject);
connect(m_dialog, &QQuickMessageDialogImpl::buttonClicked, this,