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. QML & Object.defineProperty
Forum Updated to NodeBB v4.3 + New Features

QML & Object.defineProperty

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 784 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.
  • V Offline
    V Offline
    VeNToR
    wrote on 30 Dec 2019, 22:29 last edited by
    #1

    Hi;

    How to read property of QML object that defined by Object.defineProperty from C++ ?

    QObject::property and QQmlPropertyMap already tried...

    Thnx

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 31 Dec 2019, 06:27 last edited by
      #2
      1. You need to get the c++ QObject corresponding to QML object.
      2. You need to use the combination of engine.rootObjects() & QObject children() API.
      3. Once you get the object you can fetch each property using QObject property method.
      4. Result of property function will be QVariant. This you need to convert to JSON object & use it.

      Long way...

      Why do you want to do this ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      V 1 Reply Last reply 3 Jan 2020, 22:32
      0
      • R Offline
        R Offline
        rrlopez
        wrote on 31 Dec 2019, 17:37 last edited by
        #3

        Hi, have you checked the info on this link?
        https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

        However, I would not recommend you to do that because what you say goes against the MVC design pattern that QML provides.
        Why do you want to access a QML object property from C++? I would recommend defining a Q_PROPERTY on your C++ side to be able to access it from either C++ and QML:
        https://doc.qt.io/qt-5/properties.html

        Other thing you could do is to create custom signal handling for that object. For example, if you click the object, emit a signal that is catched by your C++ class and perform necessary changes.

        Lic-Ing. Rodrigo Lopez Gonzalez
        Embedded Software Engineer
        RidgeRun Engineering Ltd.
        www.ridgerun.com
        Email: rodrigo.lopez@ridgerun.com

        V 1 Reply Last reply 3 Jan 2020, 22:33
        0
        • D dheerendra
          31 Dec 2019, 06:27
          1. You need to get the c++ QObject corresponding to QML object.
          2. You need to use the combination of engine.rootObjects() & QObject children() API.
          3. Once you get the object you can fetch each property using QObject property method.
          4. Result of property function will be QVariant. This you need to convert to JSON object & use it.

          Long way...

          Why do you want to do this ?

          V Offline
          V Offline
          VeNToR
          wrote on 3 Jan 2020, 22:32 last edited by
          #4

          @dheerendra said in QML & Object.defineProperty:

          You need to get the c++ QObject corresponding to QML object.
          You need to use the combination of engine.rootObjects() & QObject children() API.
          Once you get the object you can fetch each property using QObject property method.
          Result of property function will be QVariant. This you need to convert to JSON object & use it.

          Many thanks for your replay... Qt.bind solved my problem... Your solution is right but long way...

          Thanks again.

          1 Reply Last reply
          0
          • R rrlopez
            31 Dec 2019, 17:37

            Hi, have you checked the info on this link?
            https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

            However, I would not recommend you to do that because what you say goes against the MVC design pattern that QML provides.
            Why do you want to access a QML object property from C++? I would recommend defining a Q_PROPERTY on your C++ side to be able to access it from either C++ and QML:
            https://doc.qt.io/qt-5/properties.html

            Other thing you could do is to create custom signal handling for that object. For example, if you click the object, emit a signal that is catched by your C++ class and perform necessary changes.

            V Offline
            V Offline
            VeNToR
            wrote on 3 Jan 2020, 22:33 last edited by
            #5

            @rrlopez Many thanks for your replay too... Qt.bind solved my problem...

            1 Reply Last reply
            0

            1/5

            30 Dec 2019, 22:29

            • Login

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