summaryrefslogtreecommitdiff
path: root/src/dialogs/qquickabstractdialog.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2019-04-14 10:43:57 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-04-16 12:53:29 +0000
commita54eb316af7921ff77d4419c8b11b31f8e6fac7b (patch)
tree59752ad0e9872e2b36cd7be09d8c431d1aa699e8 /src/dialogs/qquickabstractdialog.cpp
parent1edf84eff083eb5412b4c5c7cd3bd8166f15f61f (diff)
downloadqtquickcontrols-a54eb316af7921ff77d4419c8b11b31f8e6fac7b.tar.gz
Create the decoration component when it is needed
If multiple QQmlEngines are created and use a Dialog, initalizeEngine will be called more than once and therefore recreates the QQuickAbstractDialog::m_decorationComponent without deleting the original. Therefore we keep the decoration component url instead, and create the decoration component on demand. This ensures that it keeps the component relevant for the QQmlEngine and stops the memory leak from before as well. Fixes: QTBUG-75149 Change-Id: Ic79103f42d092d39b46868a45b4099ddc6edf9db Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/dialogs/qquickabstractdialog.cpp')
-rw-r--r--src/dialogs/qquickabstractdialog.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/dialogs/qquickabstractdialog.cpp b/src/dialogs/qquickabstractdialog.cpp
index e00c17a1..e71948d1 100644
--- a/src/dialogs/qquickabstractdialog.cpp
+++ b/src/dialogs/qquickabstractdialog.cpp
@@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcWindow, "qt.quick.dialogs.window")
-QQmlComponent *QQuickAbstractDialog::m_decorationComponent(0);
+QUrl QQuickAbstractDialog::m_decorationComponentUrl = QUrl();
QQuickAbstractDialog::QQuickAbstractDialog(QObject *parent)
: QObject(parent)
@@ -151,6 +151,8 @@ void QQuickAbstractDialog::setVisible(bool v)
// If the platform does not support multiple windows, but the dialog is
// implemented as an Item, then try to decorate it as a fake window and make it visible.
if (!m_windowDecoration) {
+ if (!m_decorationComponent)
+ m_decorationComponent = new QQmlComponent(qmlEngine(this), m_decorationComponentUrl, QQmlComponent::Asynchronous, this);
if (m_decorationComponent) {
if (m_decorationComponent->isLoading())
connect(m_decorationComponent, SIGNAL(statusChanged(QQmlComponent::Status)),
@@ -232,7 +234,7 @@ void QQuickAbstractDialog::decorationLoaded()
"cannot be used as a window decoration because it's not an Item";
delete decoration;
delete m_decorationComponent;
- m_decorationComponent = 0;
+ m_decorationComponent = nullptr;
}
}
// Window decoration wasn't possible, so just reparent it into the scene