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++
Forum Update on Monday, May 27th 2025

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.
  • S Offline
    S Offline
    saitej
    wrote on 26 May 2016, 14:11 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!!

    P 1 Reply Last reply 26 May 2016, 14:53
    0
    • S saitej
      26 May 2016, 14:11

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

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 26 May 2016, 14:53 last edited by
      #2

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

      157

      S 1 Reply Last reply 26 May 2016, 15:10
      0
      • P p3c0
        26 May 2016, 14:53

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

        S Offline
        S Offline
        saitej
        wrote on 26 May 2016, 15:10 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");
        
        P 1 Reply Last reply 26 May 2016, 16:34
        0
        • S saitej
          26 May 2016, 15:10

          @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");
          
          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 26 May 2016, 16:34 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

          S 1 Reply Last reply 26 May 2016, 17:39
          0
          • P p3c0
            26 May 2016, 16:34

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

            S Offline
            S Offline
            saitej
            wrote on 26 May 2016, 17:39 last edited by saitej
            #5

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

            Viewer.qml

            Rectangle{
            id: rect
            property var MarkerList: []
            .......................
            }
            
            P 1 Reply Last reply 27 May 2016, 05:05
            0
            • S saitej
              26 May 2016, 17:39

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

              Viewer.qml

              Rectangle{
              id: rect
              property var MarkerList: []
              .......................
              }
              
              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 27 May 2016, 05:05 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

              6/6

              27 May 2016, 05:05

              • Login

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