Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Access lists from qml in c++
QtWS25 Last Chance

Access lists from qml in c++

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.3k 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.
  • saitejS Offline
    saitejS Offline
    saitej
    wrote on last edited by
    #1

    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!!

    p3c0P 1 Reply Last reply
    0
    • saitejS saitej

      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!!

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

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

      157

      saitejS 1 Reply Last reply
      0
      • p3c0P p3c0

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

        saitejS Offline
        saitejS Offline
        saitej
        wrote on last edited by
        #3

        @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");
        
        p3c0P 1 Reply Last reply
        0
        • saitejS saitej

          @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");
          
          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @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

          saitejS 1 Reply Last reply
          0
          • p3c0P p3c0

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

            saitejS Offline
            saitejS Offline
            saitej
            wrote on last edited by saitej
            #5

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

            Viewer.qml

            Rectangle{
            id: rect
            property var MarkerList: []
            .......................
            }
            
            p3c0P 1 Reply Last reply
            0
            • saitejS saitej

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

              Viewer.qml

              Rectangle{
              id: rect
              property var MarkerList: []
              .......................
              }
              
              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @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
              0

              • Login

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