diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2024-04-04 20:43:54 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2024-04-04 23:15:46 +0000 |
commit | 76928231ffa4d6394ace71aa2573293fffac954c (patch) | |
tree | d90ae1bff30fdefa703ae86a29f3789ae34fe701 | |
parent | 23982743174604be213384afeb3a5b10a0af78e3 (diff) |
QMouseHandler: fix QObject::connect() call
This connection was created in QMouseHandlerPrivate's constructor,
however at that point the `q_ptr` hadn't been initialized yet, so the
connection's 3rd parameter was null, which produced a runtime warning.
Move the initialization, and other relevant code, of the QTimer member
to init().
Drive-by change: use chrono literals; add missing include.
Amends 7671478aad2d2a48148852e9ce5a5b598a59f23d.
Pick-to: 6.7
Change-Id: I305e740617e83cf8120ffc25c67004a7dbcc1df8
Reviewed-by: David Faure <david.faure@kdab.com>
-rw-r--r-- | src/input/frontend/qmousehandler.cpp | 20 | ||||
-rw-r--r-- | src/input/frontend/qmousehandler_p.h | 3 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/input/frontend/qmousehandler.cpp b/src/input/frontend/qmousehandler.cpp index c2554dc4b..175b6cc45 100644 --- a/src/input/frontend/qmousehandler.cpp +++ b/src/input/frontend/qmousehandler.cpp @@ -13,29 +13,31 @@ QT_BEGIN_NAMESPACE namespace Qt3DInput { using namespace Qt3DCore; +using namespace std::chrono_literals; /*! \internal */ QMouseHandlerPrivate::QMouseHandlerPrivate() : QComponentPrivate() , m_mouseDevice(nullptr) , m_containsMouse(false) - , m_pressAndHoldTimer(new QTimer) { m_shareable = false; - m_pressAndHoldTimer->setSingleShot(true); - m_pressAndHoldTimer->setInterval(800); - QObject::connect(m_pressAndHoldTimer, &QTimer::timeout, q_func(), [this] { - emit q_func()->pressAndHold(m_lastPressedEvent.data()); - }); } QMouseHandlerPrivate::~QMouseHandlerPrivate() { } -void QMouseHandlerPrivate::init(QObject *parent) +void QMouseHandlerPrivate::init() { - m_pressAndHoldTimer->setParent(parent); + Q_Q(QMouseHandler); + + m_pressAndHoldTimer = new QTimer(q); + m_pressAndHoldTimer->setSingleShot(true); + m_pressAndHoldTimer->setInterval(800ms); + QObject::connect(m_pressAndHoldTimer, &QTimer::timeout, q, [this, q] { + emit q->pressAndHold(m_lastPressedEvent.data()); + }); } void QMouseHandlerPrivate::mouseEvent(const QMouseEventPtr &event) @@ -230,7 +232,7 @@ QMouseHandler::QMouseHandler(QNode *parent) : QComponent(*new QMouseHandlerPrivate, parent) { Q_D(QMouseHandler); - d->init(this); + d->init(); } QMouseHandler::~QMouseHandler() diff --git a/src/input/frontend/qmousehandler_p.h b/src/input/frontend/qmousehandler_p.h index 2dc444492..03ff6f4d1 100644 --- a/src/input/frontend/qmousehandler_p.h +++ b/src/input/frontend/qmousehandler_p.h @@ -16,6 +16,7 @@ // #include <Qt3DInput/qmouseevent.h> +#include <Qt3DInput/qmousehandler.h> #include <Qt3DCore/private/qcomponent_p.h> @@ -34,7 +35,7 @@ public: QMouseHandlerPrivate(); ~QMouseHandlerPrivate(); - void init(QObject *parent); + void init(); QMouseDevice *m_mouseDevice; bool m_containsMouse; |