Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to find nested QML objects for C++

    QML and Qt Quick
    3
    5
    1291
    Loading More Posts
    • 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
      RyonMS last edited by 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 1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        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 Reply Quote 2
        • C
          c64zottel @RyonMS last edited by

          @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 Reply Quote 0
          • R
            RyonMS @sierdzio last edited by

            @sierdzio That did it! Thanks!

            1 Reply Last reply Reply Quote 1
            • sierdzio
              sierdzio Moderators last edited by

              Nice! Happy coding!

              (Z(:^

              1 Reply Last reply Reply Quote 0
              • First post
                Last post