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. How to find nested QML objects for C++
QtWS25 Last Chance

How to find nested QML objects for C++

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

    So I have QML file with a StackView and a Rectangle and ListView nested inside. The Rectangle and ListView have signals that I want to connect in C++ but I am unsure of how to get them. I have a view in C++ and I tried doing view.findChild<QObject*>("objectName") but it comes back NULL. Each of the QML objects have a unique id and objectName assigned to them so I can't figure out what I am doing wrong. If someone could offer some suggestions, I would greatly appreciate it.

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

      This is what the docs say:

      Delegates are instantiated as needed and may be destroyed at any time. They are parented to ListView's contentItem, not to the view itself. State should never be stored in a delegate.

      So, I think you should first find the content item and then run findChild() on that object.

      (Z(:^

      R 1 Reply Last reply
      2
      • R RyonMS

        So I have QML file with a StackView and a Rectangle and ListView nested inside. The Rectangle and ListView have signals that I want to connect in C++ but I am unsure of how to get them. I have a view in C++ and I tried doing view.findChild<QObject*>("objectName") but it comes back NULL. Each of the QML objects have a unique id and objectName assigned to them so I can't figure out what I am doing wrong. If someone could offer some suggestions, I would greatly appreciate it.

        C Offline
        C Offline
        c64zottel
        wrote on last edited by
        #3

        @RyonMS Could you elaborate on your question? It is unclear to me what you are trying to do. You say you have a C++ view, which you want to connect to a Rectangle and ListView?

        Maybe it's a good idea to describe your use case. Does the user clicks on an item in the ListView and you want that item to appear more detailed somewhere else?

        1 Reply Last reply
        0
        • sierdzioS sierdzio

          This is what the docs say:

          Delegates are instantiated as needed and may be destroyed at any time. They are parented to ListView's contentItem, not to the view itself. State should never be stored in a delegate.

          So, I think you should first find the content item and then run findChild() on that object.

          R Offline
          R Offline
          RyonMS
          wrote on last edited by
          #4

          @sierdzio That did it! Thanks!

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

            Nice! Happy coding!

            (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