Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QEvent in qml

QEvent in qml

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bundickt
    wrote on last edited by
    #1

    Is there a way to pass a QEvent, QKeyEvent or QMouseEvent from c++ to qml without writing my own wrapper classes?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      You will need to wrap them in some fashion (you can see the wrappers used by the built-in elements at src/declarative/graphicsitems/qdeclarativeevents_p.h).

      Regards,
      Michael

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bundickt
        wrote on last edited by
        #3

        Thanks Michael

        I implemented wrappers similar to the ones in qdeclarativeevents_p.h but when I try to use them in my qml I get this error:

        QMetaProperty::read: Unable to handle unregistered datatype 'QMLKeyEvent*' for property 'QDeclarativeBoundSignalParameters::event'

        I register the QMLKeyEvent class with this call:

        @
        qmlRegisterType<QMLKeyEvent>();
        @

        And at the end of my header file that contains the QMLKeyEvent class I put:

        @
        QML_DECLARE_TYPE(QMLKeyEvent)
        @

        Is there something else I need to do to register this type?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          I can't think of anything else you'd need to do.

          What version of Qt are you running (there have been a lot of bug fixes since 4.7.0)? Can you share what your QML looks like?

          Regards,
          Michael

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bundickt
            wrote on last edited by
            #5

            I believe I'm using Qt 4.7.1.

            My QML code looks like this:

            @
            UserEventFilter {
            id: userEventFilter;

            onKeyPressed: {
            console.log(event.text);
            }
            }
            @

            UserEventFilter code looks like this:

            @
            bool UserEventFilter::processKeyPress(QEvent *event) {
            QMLKeyEvent ke(*static_cast<QKeyEvent *>(event));
            ke.setAccepted(false);

            emit keyPressed(&ke);
            emit userEventOccurred();

            return ke.isAccepted();
            }
            @

            I'm going to upgrade to Qt 4.7.2 and see what happens.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bundickt
              wrote on last edited by
              #6

              Are there any examples out there that show how to emit a signal with an argument that is not a basic type?
              Also, are there examples of emitting a signal with an argument that is not read only?

              1 Reply Last reply
              0
              • B Offline
                B Offline
                bundickt
                wrote on last edited by
                #7

                It's working... I think I had something wrong with my build.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved