Details
-
Task
-
Resolution: Unresolved
-
P4: Low
-
None
Description
The logic with PointerHandlers goes like this:
1) QPointerEvent will inherit from QEvent (because we want it that way in Qt 6), and other more-specific events inherit from that
2) QEvent is not a QObject, for good reason
3) In QtQuick, we want to have properties on events
4) So, the event should be a gadget
5) I have been told a gadget must always be passed by value from C++ to QML, not by pointer (and my experiment to pass it by pointer in fact did not work)
6) We want to send the event as a signal parameter: MouseArea.onPressed receives the event, so analogously, PointerHandler.onPressed should receive the event too
7) Ta-da - lots and lots of event copying is going on. We visit lots of handlers, emit the signal a lot, and each time, it's a copy. Is that bad? The basic pointer event is now about 11 64-bit words in size (plus whatever it inherits from QEvent). Bigger than one cache line.
Contrast that with Erik's (awesome) hack for the QQuickMouseEvent (and others): it's a QObject, and we cannot change that because it has a setAccepted() method (you can set the accepted property). We need to pass it by pointer in order to check the accepted value after returning from the JS handler. Otherwise, it would be fine for it to be a gadget. So Erik made it at least reuse the same object instance all the time, instead of constantly making new ones. Probably it's more efficient to have it be a QObject and pass it by pointer than copying a gadget, actually. https://codereview.qt-project.org/#/c/158887/
But events should be plain objects, and we don't want events in QtQuick to be "special": they should be the original ones.
I'd like them to be emitted by pointer, though, to avoid all the copying.
Either way, they are stack allocated, not heap allocated, so we are saving something there.
Attachments
Issue Links
- is duplicated by
-
QTBUG-79640 Q_GADGETs can't be used as Pointers in QML
- Closed
- relates to
-
QTBUG-54983 Create Q_GADGET objects in QML
- Closed
-
QTBUG-91350 [REG 5.15->6.0] TapHandler.onTapped: device and button are no longer available
- Closed
-
QTBUG-72223 Make it possible to declare Q_GADGET instances in QML
- Open
-
QTBUG-79330 Improve handling of Q_GADGETs in QML
- Open
Gerrit Reviews
For Gerrit Dashboard: QTBUG-54321 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
307023,6 | WIP Add Q_GADGET and property declarations to event classes | dev | qt/qtbase | Status: DEFERRED | -2 | 0 |