Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-54321

Is it really impossible to pass a Q_GADGET by pointer to QML?

    XMLWordPrintable

Details

    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

          For Gerrit Dashboard: QTBUG-54321
          # Subject Branch Project Status CR V

          Activity

            People

              ulherman Ulf Hermann
              srutledg Shawn Rutledge
              Votes:
              2 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes