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. accessing attributes of qml elements from c++
Forum Updated to NodeBB v4.3 + New Features

accessing attributes of qml elements from c++

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.2k 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.
  • R Offline
    R Offline
    rockstar
    wrote on last edited by
    #1

    how to access predefined attributes of qml elements from c++......for example,in my case how to access mouseX,mouseY of mousearea from c++ file......

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      It's all explained in the documentation. Basically, you have to extract your MouseArea object from rootContext, and then get the property value using the Meta Object System.

      Here's on of relevant docs: "link":http://developer.qt.nokia.com/doc/qt-4.8/qtbinding.html#exchanging-data-between-qml-and-c.

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rockstar
        wrote on last edited by
        #3

        @QObject *mousearea=rect->findChild<QObject *>("mouse");
        qDebug()<<"position:"<<mousearea->property("mouseX").toDouble()<<","<<mousearea->property("mouseY").toDouble();@

        this is what i wrote........but when i am executing the code i ma getting don't send error(i am in windows by the way).....

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rockstar
          wrote on last edited by
          #4

          ok ok....now that error has gone but i am getting (0,0) at each and every position.....any reason???

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            Do you have "hoverEnabled" property set to true? If not, mouse is not being tracked, and you'll get (0,0) every time.

            (Z(:^

            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