Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Solved Access lists from qml in c++

    General and Desktop
    2
    6
    1007
    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.
    • saitej
      saitej last edited by

      I have a list which are in a qml widget and the widget is called in the mainwindow.
      Mainwindow snippet:

      QQuickWidget *widget = new QQuickWidget;
      widget->setSource(QUrl(QStringLiteral("qrc:/qml_maps/Viewer.qml")));
      

      The lists can be accessed in Viewer.qml. How do I access it in a different c++ class.

      Thanks!!

      p3c0 1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators @saitej last edited by

        @saitej Use findChild to access the object containing the list by object name. Then cast it to QList

        157

        saitej 1 Reply Last reply Reply Quote 0
        • saitej
          saitej @p3c0 last edited by

          @p3c0
          Ya I had tried this way already. I m not sure of the syntax

          QQuickWidget *widget = new QQuickWidget;
          widget->setSource(QUrl(QStringLiteral("qrc:/qml_maps/Viewer.qml")));
            QList l1;
              l1 = widget->findChild<QList *>("MarkerList");
          
          p3c0 1 Reply Last reply Reply Quote 0
          • p3c0
            p3c0 Moderators @saitej last edited by

            @saitej
            What is MarkerList ? By list do you mean ListView ?
            If that's the case then you will need to cast it to QQuickItem.

            157

            saitej 1 Reply Last reply Reply Quote 0
            • saitej
              saitej @p3c0 last edited by saitej

              @p3c0
              No. Its an array (property of the viewer)

              Viewer.qml

              Rectangle{
              id: rect
              property var MarkerList: []
              .......................
              }
              
              p3c0 1 Reply Last reply Reply Quote 0
              • p3c0
                p3c0 Moderators @saitej last edited by

                @saitej Ok. Then find rect using findChild. You will need to provide an objectName to it. After that since MarkerList is a property you can access it using property. Then convert this returned QVariant to QList.

                157

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