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 QML Properties when object is instantiated as a quickWidget through QtDesigner
Forum Updated to NodeBB v4.3 + New Features

Accessing QML Properties when object is instantiated as a quickWidget through QtDesigner

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 589 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.
  • J Offline
    J Offline
    Jeng22
    wrote on 6 Jun 2019, 16:38 last edited by
    #1

    I wrote a tumbler module in QML that is setting date/time fields that I would like to access in C++. Originally the project was written using .ui files in QtDesigner, so I incorporated the tumbler module as a quickWidget and set the source url. I tried using different approaches like signals/slots and Q_Properties, but have not found success. Any help would be greatly appreciated as I am relatively new to using Qt!

    QML Properties to be accessed:
    0_1559838836844_5cefb4b7-2bfc-4dac-bca8-222084fd1495-image.png

    C++ File
    0_1559838899390_56d4c45e-0288-4caf-9493-dac0e3534777-image.png

    Tumbler Module inserted into .ui file as a quickWidget
    0_1559838993294_c693e90d-5127-4c9b-8e5a-f7cf6fe13c22-image.png

    I am probably missing some important information, so let me know. Thanks!

    K 1 Reply Last reply 7 Jun 2019, 04:16
    0
    • J Jeng22
      6 Jun 2019, 16:38

      I wrote a tumbler module in QML that is setting date/time fields that I would like to access in C++. Originally the project was written using .ui files in QtDesigner, so I incorporated the tumbler module as a quickWidget and set the source url. I tried using different approaches like signals/slots and Q_Properties, but have not found success. Any help would be greatly appreciated as I am relatively new to using Qt!

      QML Properties to be accessed:
      0_1559838836844_5cefb4b7-2bfc-4dac-bca8-222084fd1495-image.png

      C++ File
      0_1559838899390_56d4c45e-0288-4caf-9493-dac0e3534777-image.png

      Tumbler Module inserted into .ui file as a quickWidget
      0_1559838993294_c693e90d-5127-4c9b-8e5a-f7cf6fe13c22-image.png

      I am probably missing some important information, so let me know. Thanks!

      K Offline
      K Offline
      KillerSmath
      wrote on 7 Jun 2019, 04:16 last edited by KillerSmath 6 Jul 2019, 04:16
      #2

      @Jeng22

      The updateComponent is not directly declared in QQuickWidget, instead of it, QQuickWidget has a item called RootObject that represent the first item on your view.

      Beyong that, you must think in hierarchy of your qml file.

      1. If the tumbler module is the root object of your widget as below than you can directly access it from rootObject.
      • QQuickWidget
        • Root Item
      Item{
          // Your properties and signals
      }
      
      QObject *item = ui->quickWidget->rootObject();
      QObject::connect(item, SIGNAL(updateComponent(QString)), this, SLOT(handleUpdateComponent(QString)));
      

      1. On the other hand, if your module is inside of another object than you may set objectName property and find it from rootObject
      • QQuickWidget
        • Root Item
          • Inner Item
      Item{
          Item{
              objectName: "InnerObject"
             // your properties and signals
          }
      }
      
      QObject *item = quickWidget.rootObject()->findChild<QObject *>("InnerObject");
      QObject::connect(item, SIGNAL(updateComponent(QString)), this, SLOT(handleUpdateComponent(QString)));
      

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      1 Reply Last reply
      3
      • J Offline
        J Offline
        Jeng22
        wrote on 7 Jun 2019, 14:54 last edited by
        #3

        @KillerSmath Thanks for the reply! That makes more sense. My object is at root so I went with the first approach.

        I got it working now, thanks for the help!

        1 Reply Last reply
        0

        1/3

        6 Jun 2019, 16:38

        • Login

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