diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-07-15 16:51:41 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-07-18 09:53:53 +0000 |
commit | a5b14886968ad258921aeb719710744d99d0a464 (patch) | |
tree | fe547c96adba629ad2892aa109762f5f91855ca6 | |
parent | 11933cbeca4ce1cd47e790644dc522db227d4b8e (diff) |
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 <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquicktooltip.cpp | 13 | ||||
-rw-r--r-- | src/quicktemplates2/qquicktooltip_p.h | 2 |
2 files changed, 7 insertions, 8 deletions
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<QQuickItem *>(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<QQuickItem *>(parent); + if (!item && parent) + qmlInfo(parent) << "ToolTip must be attached to an Item"; } /*! diff --git a/src/quicktemplates2/qquicktooltip_p.h b/src/quicktemplates2/qquicktooltip_p.h index 227c6a4e..96c75c3b 100644 --- a/src/quicktemplates2/qquicktooltip_p.h +++ b/src/quicktemplates2/qquicktooltip_p.h @@ -111,7 +111,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickToolTipAttached : public QObject Q_PROPERTY(QQuickToolTip *toolTip READ toolTip CONSTANT FINAL) public: - explicit QQuickToolTipAttached(QQuickItem *item); + explicit QQuickToolTipAttached(QObject *parent = nullptr); QString text() const; void setText(const QString &text); |