From ee2ac69595d3f854f7bf7158e600091f2675fa18 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 22 Nov 2018 14:00:39 +0100 Subject: Add dynamically-created Event Handlers to the relevant handlers vector If any kind of Pointer Handler is created dynamically in JS by calling Component.createObject(), QObject::setParent() is called rather than passing the parent to the constructor, so QQuickItemPrivate::data_append() did not take care of adding the handler to QQuickItemPrivate's extra->pointerHandlers vector. We need to use the auto-parent mechanism (just as we did with handling dynamic creation of nested Windows in 8cb02e23abbefc9d020707fc1a2d8b6eb4e103b6). Added QQuickItemPrivate::addPointerHandler() to put the prepend() and implied setAcceptedMouseButtons() in one place. Fixes: QTBUG-71427 Change-Id: I3be3dd033c1c89e6e5b5c3463e1a720bbe963281 Reviewed-by: Shawn Rutledge --- src/quick/items/qquickitemsmodule.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/quick/items/qquickitemsmodule.cpp') diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index a20150e3b9..b2fcfb4307 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -145,6 +145,7 @@ static QQmlPrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject return QQmlPrivate::Parented; } } else if (QQuickPointerHandler *handler = qmlobject_cast(obj)) { + QQuickItemPrivate::get(parentItem)->addPointerHandler(handler); handler->setParent(parent); return QQmlPrivate::Parented; } @@ -156,13 +157,14 @@ static QQmlPrivate::AutoParentResult qquickitem_autoParent(QObject *obj, QObject qCDebug(lcTransient) << win << "is transient for" << parentWindow; win->setTransientParent(parentWindow); return QQmlPrivate::Parented; - } else { - QQuickItem *item = qmlobject_cast(obj); - if (item) { - // The parent of an Item inside a Window is actually the implicit content Item - item->setParentItem(parentWindow->contentItem()); - return QQmlPrivate::Parented; - } + } else if (QQuickItem *item = qmlobject_cast(obj)) { + // The parent of an Item inside a Window is actually the implicit content Item + item->setParentItem(parentWindow->contentItem()); + return QQmlPrivate::Parented; + } else if (QQuickPointerHandler *handler = qmlobject_cast(obj)) { + QQuickItemPrivate::get(parentWindow->contentItem())->addPointerHandler(handler); + handler->setParent(parentWindow->contentItem()); + return QQmlPrivate::Parented; } return QQmlPrivate::IncompatibleObject; } else if (qmlobject_cast(obj)) { -- cgit v1.2.3