diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-08-19 17:42:15 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-08-22 08:01:44 +0000 |
commit | 53c780f15c2d170514f74d949a8165033275bddd (patch) | |
tree | 9b3f4b47d51ee1f04fe5379a8670b4645b0d47dc /src/quicktemplates2/qquicktooltip.cpp | |
parent | 449a655fd7c1b049ea2cc57033987a2556aadcd8 (diff) |
QQuickToolTip: fix the creation context of the shared tooltip
Don't create the shared tooltip in the parent item's context, because
that may be destroyed and invalidate all bindings in ToolTip.qml. The
QML engine is the effective parent of the shared tooltip, so use the
engine's root context for creation as well. We do not need to pass any
specific context to QQmlComponent::create(), because it will pick the
root context by default.
Change-Id: I624b53fa9ba02123398e76b5eccf1a8091826b37
Task-number: QTBUG-55347
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquicktooltip.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktooltip.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index d47589ba..e08078f6 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -334,21 +334,18 @@ QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const 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); - if (context) { - QQmlComponent component(context->engine()); - 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)); - } + QQmlComponent component(engine); + component.setData("import QtQuick.Controls 2.0; ToolTip { }", QUrl()); + + QObject *object = component.create(); + if (object) + object->setParent(engine); + + tip = qobject_cast<QQuickToolTip *>(object); + if (!tip) + delete object; + else + engine->setProperty(name, QVariant::fromValue(object)); } return tip; } |