Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QVariantList Repeater



  • Hello,
    I try to pass a QJsonArray from C++ to QML via QVariantList and mark positions on a map. For these purpose I developed this code in QML:

    Map {
          id: id_quizMap
          plugin: mapPlugin
    
          Repeater {
              model: quizfiles.getLocations
    
              MapQuickItem {
                  id: id_marker
                  anchorPoint.x: id_positionImage.width/2
                  anchorPoint.y: id_positionImage.height
                  coordinate: QtPositioning.coordinate(this.value("Lat"), this.value("Long"))
    
                  sourceItem: Image {
                      id: id_quizImage
                      width: sourceSize.width*2
                      height: sourceSize.height*2
                      source: "images/map-question-marker.svg"
                  }
              }
          }
      }
    

    if I output the array returned of quizFiles.getLocations i get this output:

    D libXy.so: QVariant(QVariantMap, QMap(("GameFolder", QVariant(QString, "Titel1"))("GameType", QVariant(QString, "Quiz"))("Group", QVariant(double, 1))("Lat", QVariant(QString, "49.452943614253059"))("LocationName", QVariant(QString, "THN"))("Long", QVariant(QString, "11.097496110845555"))("Status", QVariant(QString, "Open"))))
    D libXy.so: QVariant(QVariantMap, QMap(("GameFolder", QVariant(QString, "story1"))("GameType", QVariant(QString, "Story"))("Group", QVariant(double, 1))("Lat", QVariant(QString, "49.452384329402705"))("LocationName", QVariant(QString, "see"))("Long", QVariant(QString, "11.100266172564261"))("Status", QVariant(QString, "Open"))))
    D libXy.so: QVariant(QVariantMap, QMap(("GameFolder", QVariant(QString, "sdvgs"))("GameType", QVariant(QString, "Quiz"))("Group", QVariant(double, 2))("Lat", QVariant(QString, "49.451013526379832"))("LocationName", QVariant(QString, "bridge"))("Long", QVariant(QString, "11.097201596953937"))("Status", QVariant(QString, "Open"))))
    D libXy.so: QVariant(QVariantMap, QMap(("GameFolder", QVariant(QString, "dfbsdg"))("GameType", QVariant(QString, "Quiz"))("Group", QVariant(double, 2))("Lat", QVariant(QString, "49.452431345885934"))("LocationName", QVariant(QString, "mensa"))("Long", QVariant(QString, "11.094536577839790"))("Status", QVariant(QString, "Open"))))
    D libXy.so: Locations:  QVariant(QVariantMap, QMap(("GameFolder", QVariant(QString, "fbgfnfghn"))("GameType", QVariant(QString, "Quiz"))("Group", QVariant(double, 3))("Lat", QVariant(QString, "49.457294201293251"))("LocationName", QVariant(QString, "vcasdcvasj"))("Long", QVariant(QString, "11.058210966587012"))("Status", QVariant(QString, "Open"))))
    D libXy.so: Locations:  QVariant(QVariantMap, QMap(("GameFolder", QVariant(QString, "Ziel"))("GameType", QVariant(QString, ""))("Group", QVariant(double, 4))("Lat", QVariant(QString, "49.455508850240328"))("LocationName", QVariant(QString, "Ziel"))("Long", QVariant(QString, "11.097349760532325"))("Status", QVariant(QString, "Open"))))
    

    But there is no marker on the map and I dont know, whats my fault.


  • Qt Champions 2018

    Linking you one of my answer on SO https://stackoverflow.com/a/45550835/2788674

    TL;DR: use MapItemView instead of Repeater in a Map.



  • Thanks for your answer GrecKo, know it works with this code:

    Map {
          id: id_quizMap
          plugin: mapPlugin
    
          MapItemView {
              id: id_mapViewQuizMarker
              model: quizfiles.getLocations
              delegate: id_quizDelegate
          }
    
          Component {
              id: id_quizDelegate
    
              MapQuickItem {
                  id: id_marker
                  anchorPoint.x: id_positionImage.width/2
                  anchorPoint.y: id_positionImage.height
                  coordinate: QtPositioning.coordinate(id_mapViewQuizMarker.model[index].Lat, id_mapViewQuizMarker.model[index].Long)
    
                  sourceItem: Image {
                      id: id_quizImage
                      width: sourceSize.width*2
                      height: sourceSize.height*2
                      source: "images/map-question-marker.svg"
                  }
              }
          }
      }
    

Log in to reply