aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-08-18 16:12:27 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-08-19 10:32:27 +0000
commit93b68f9a12198f226a8d59717bc1cd36d47c5dbe (patch)
treeb7234cc442819a43c575f40e53cbb0d723e040cb
parent7c07c60ff17974621fea932a18cc2e652d17ab78 (diff)
QQuickToolTip: fix destruction of the shared tooltip
Make the QML engine the parent of the shared tooltip instance, and make sure the instances are per engine. This ensures that the shared tooltip gets properly destructed when the associated QML engine is destructed. The same technique is used for the global styles in QQuickStyleAttached. Change-Id: I08dcb4f9bc6ddafb7449afe43362e560c0952e88 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquicktooltip.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp
index cc0b6350..65e81fda 100644
--- a/src/quicktemplates2/qquicktooltip.cpp
+++ b/src/quicktemplates2/qquicktooltip.cpp
@@ -325,7 +325,13 @@ public:
QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const
{
- static QPointer<QQuickToolTip> tip;
+ QQmlEngine *engine = qmlEngine(parent);
+ if (!engine)
+ return nullptr;
+
+ static const char *name = "_q_QQuickToolTip";
+
+ QQuickToolTip *tip = engine->property(name).value<QQuickToolTip *>();
if (!tip && create) {
// TODO: a cleaner way to create the instance? QQml(Meta)Type?
QQmlContext *context = qmlContext(parent);
@@ -334,9 +340,14 @@ QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const
component.setData("import QtQuick.Controls 2.0; ToolTip { }", QUrl());
QObject *object = component.create(context);
+ if (object)
+ object->setParent(engine);
+
tip = qobject_cast<QQuickToolTip *>(object);
if (!tip)
delete object;
+ else
+ engine->setProperty(name, QVariant::fromValue(object));
}
}
return tip;