Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Can I dynamically add a MapGroup to a Map?
Qt 6.11 is out! See what's new in the release blog

Can I dynamically add a MapGroup to a Map?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.3k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have managed to dynamically add MapImages to a map but fail to add MapGroups. Is there something I am missing ?

    the javascript code used to add the component is the following :

    @var component = Qt.createComponent("Station.qml");
    for(var i=0;i<stationsXMLModel.count;i++){
    var object = component.createObject(mapview, {
    "latitude": stationsXMLModel.get(i).latitude,
    "longitude": stationsXMLModel.get(i).longitude,
    "number":stationsXMLModel.get(i).number});
    if (object.status == Component.Ready) {
    stationsArray.push(object);
    }
    if (object.status == Component.Error) {
    console.log("Error: " + component.errorString());
    }
    }@

    When "Station.qml" contains a MapImage (see below), everything works as expected

    @MapImage {
    source: "images/station.png"
    property alias latitude: mapMarkerCoordinate.latitude
    property alias longitude: mapMarkerCoordinate.longitude
    property int number
    coordinate: Coordinate { id: mapMarkerCoordinate }
    offset.x: -24
    offset.y: -48
    }@

    But if it is a MapGroup (see below), "object.status" reads "undefined".

    @MapGroup {
    property alias latitude: mapMarkerCoordinate.latitude
    property alias longitude: mapMarkerCoordinate.longitude
    property int number

    MapImage{
    source:  "images/station.png"
    coordinate: Coordinate { id: mapMarkerCoordinate }
    offset.x: -24
    offset.y: -48
    }
    

    }@

    What am Missing ? Is there any restriction on the type of QML that can be loaded dynamically ?

    Thanks for your help,

    Olivier

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      After calling Qt.createComponent, can you console.log(component.errorString()) to ensure that it was compiled correctly? I don't know much/anything about the location/maps module, so I don't know what specifically could be wrong.

      /edit: presumably MapImage has a "status" property, while the MapGroup element does not? I'm not sure.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Thanks for your reply.

        The component.errorString() unfortunately reports an empty string.

        Any hint ?

        Olivier

        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