From a5b14886968ad258921aeb719710744d99d0a464 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 15 Jul 2016 16:51:41 +0200 Subject: ToolTip: don't leak memory if attached to a non-Item Previously, it was casting the attachee object to an item and passing it as a parent to the QObject constructor. When attached to a non-Item, it passed a null pointer as a parent. Change-Id: I45933e39e3080ab8e010fa3f7257fdffce4db685 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquicktooltip.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/quicktemplates2/qquicktooltip.cpp') diff --git a/src/quicktemplates2/qquicktooltip.cpp b/src/quicktemplates2/qquicktooltip.cpp index 42ae8edd..6b51de95 100644 --- a/src/quicktemplates2/qquicktooltip.cpp +++ b/src/quicktemplates2/qquicktooltip.cpp @@ -245,11 +245,7 @@ void QQuickToolTip::setTimeout(int timeout) QQuickToolTipAttached *QQuickToolTip::qmlAttachedProperties(QObject *object) { - QQuickItem *item = qobject_cast(object); - if (!item) - qmlInfo(object) << "ToolTip must be attached to an Item"; - - return new QQuickToolTipAttached(item); + return new QQuickToolTipAttached(object); } void QQuickToolTip::open() @@ -341,9 +337,12 @@ QQuickToolTip *QQuickToolTipAttachedPrivate::instance(bool create) const return tip; } -QQuickToolTipAttached::QQuickToolTipAttached(QQuickItem *item) : - QObject(*(new QQuickToolTipAttachedPrivate), item) +QQuickToolTipAttached::QQuickToolTipAttached(QObject *parent) : + QObject(*(new QQuickToolTipAttachedPrivate), parent) { + QQuickItem *item = qobject_cast(parent); + if (!item && parent) + qmlInfo(parent) << "ToolTip must be attached to an Item"; } /*! -- cgit v1.2.3