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. Can qml signal parameter MouseEvent be mapped to C++ class?
Forum Updated to NodeBB v4.3 + New Features

Can qml signal parameter MouseEvent be mapped to C++ class?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 3.7k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    ledunkang
    wrote on last edited by
    #1

    I've a qml signal with MouseEvent as parameter, for example, 'clicked(var mouse)',and mouse is passed from MouseArea::onClicked(MouseEvent mouse).
    I tried to connect this signal to some slot in c++ like this,
    @connect(qmlOblect, SIGNAL(clicked(QMouseEvent*)),SLOT(onClicked(QMouseEvent*)));@

    When linking, qtcreator complains that No such signal in qmlObj.
    I wonder whether qml MouseEvent can be mapped to c++ class QmouseEvent, or perhaps I missed something here?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      MouseEvent from QML is QQuickMouseEvent, not QMouseEvent. It's a private class though, and I'm not sure if it's meant to be used in C++.

      What are you trying to do?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • L Offline
        L Offline
        ledunkang
        wrote on last edited by
        #3

        I want to connect qml mouseevent signal to c++ slot in my c++ code. so that i can process logical staff related to qml mouse event in c++.
        Since QMouseEvent is not correct and QQuickMouseEvent is private, I've to define a new QObject-derived class samiliar to QMouseEvent/QQuickMouseEvent and register it to qml context. Is this right?

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xander84
          wrote on last edited by
          #4

          I don't think that will work if you use a custom event class.
          Why not use the arguments you need from the mouse event and only pass those to the c++ slot? e.g. only the position x/y as qreal or whatever you need from the event.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            ledunkang
            wrote on last edited by
            #5

            @Xander84
            Yes, you're right. I've done like what you suggested. It works. Thank u.

            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