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. QML MapView

QML MapView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 3 Posters 558 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.
  • K Offline
    K Offline
    Kory
    wrote on 11 Feb 2025, 15:44 last edited by Kory 2 Nov 2025, 16:15
    #1

    Hello, I'm exploring use of MapView{} and it's almost working how I'd like it to. I've found that it can work within a ScrollView{} and so forth, without user scrolling down stopping the user from interacting with map unlike the Map{}

    Suppose that we have a QML file called "StreetMap.qml"
    I've tried to cut out the irrelevant code. Just picture it has nesting like this

    Item {
        id: _map_container
        property var coordinate: QtPositioning.coordinate(latitude, longitude)
    
        Plugin  {
            id: myPlugin
        }
    
    
        MapView {
            anchors.fill: parent
    
            map {
                plugin: myPlugin
                center: _map_container.coordinate
                }
            }
    }
    

    The problem I'm having is if I add a MapQuickItem nested in our map {}

    MapQuickItem {
                id: marker
                coordinate:  _map_container.coordinate
                anchorPoint.x: 10
                anchorPoint.y: 10
    
                sourceItem: Image {
                    source: "qrc:/MapsModule/map_marker.png"
                    width: 24
                    height: 24
                    fillMode: Image.PreserveAspectFit
                    smooth: true
                }
    
                // Debugging: Log where the marker is placed
                Component.onCompleted: {
                    console.log("Marker placed at latitude: " + _map_container.latitude + ", longitude: " + _map_container.longitude)
                }
            }
    

    The map no longer renders. I see this error message

    W/default : qrc:/MapsModule/StreetMap.qml:78 Cannot assign a value directly to a grouped property
    

    If I have MapQuickItem nested in our MapView {}, not the map{} then the map renders and it says that the marker is at the latitude and longitude we want from our console.log but nothing is rendered on the screen at this position

    If I have MapQuickItem nested in a Map {} (not a map{}) and there's no MapView {} at all then the Map{} and MapQuickItem{} renders on the screen but I lose the features provided from the MapView{} like the interactive movement


    Perhaps it's not possible to have a MapQuickItem in a map in a map view or perhaps there's a problem with how I'm approaching this


    Let me know if you have any idea what this "Cannot assign a value directly to a grouped property" means and if there's any way around it or whatever else might be making the map unavailable the moment we have our MapQuickItem{} in a map{} of a MapView{}

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kai Nickel
      wrote on 12 Feb 2025, 14:17 last edited by
      #6

      I think you should not try to redefine the map instance that is already contained in MapView.
      Maybe this works:

      MapView {
          id: myMapView
          map.plugin: myPlugin
          map.center: _map_container.coordinate
          ...
      
          MapQuickItem {
              parent: myMapView.map
              ...
          }
      }
      
      
      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrecKo
        Qt Champions 2018
        wrote on 11 Feb 2025, 16:05 last edited by
        #2

        I think the problem is the grouped property syntax (map { ... }) as mentioned in the error message, try the following instead:

        MapView {
            map: Map {
                MapQuickItem {}
            }
        }
        
        K 1 Reply Last reply 11 Feb 2025, 16:38
        0
        • G GrecKo
          11 Feb 2025, 16:05

          I think the problem is the grouped property syntax (map { ... }) as mentioned in the error message, try the following instead:

          MapView {
              map: Map {
                  MapQuickItem {}
              }
          }
          
          K Offline
          K Offline
          Kory
          wrote on 11 Feb 2025, 16:38 last edited by Kory 2 Nov 2025, 16:38
          #3

          Hello, I tested it out

          @GrecKo said in QML MapView:

          map: Map

          I saw this warning when trying that and it dies on run

          Cannot assign object of type Map to  [incompatible-type]
          
          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kai Nickel
            wrote on 12 Feb 2025, 10:14 last edited by
            #4

            I think it is correct for the MapQuickItems to be parented to the Map, not to the MapView.

            What line actually is the one from the error message (StreetMap.qml:78)?

            I do it this way, but it might be unrelated:

            map.plugin: myPlugin
            map.center: _map_container.coordinate
            
            K 1 Reply Last reply 12 Feb 2025, 12:45
            0
            • K Kai Nickel
              12 Feb 2025, 10:14

              I think it is correct for the MapQuickItems to be parented to the Map, not to the MapView.

              What line actually is the one from the error message (StreetMap.qml:78)?

              I do it this way, but it might be unrelated:

              map.plugin: myPlugin
              map.center: _map_container.coordinate
              
              K Offline
              K Offline
              Kory
              wrote on 12 Feb 2025, 12:45 last edited by
              #5

              Hello Kai, I believe so too

              @Kai-Nickel

              Here's the exact output I see

              Note that the complaint about the StackView is really a side effect of the other complaint of not being able to assign a value directly to a grouped property

              d86a1f98-0875-4c52-b630-d5e157223d25-image.png

              In case, it's not possible, I also posted this as a suggestion
              https://bugreports.qt.io/browse/QTBUG-133696

              And have full code posted there as a .txt file

              Perhaps if it's not possible too, I believe it might be possible to use a GeocodeModel {} and MapRoute {} to have it set-up so can show route between a beginning and end destination with both points marked on the map (but I'm new to using Qt Location so don't quote me on that). If so, that could be an alternative approach I could explore instead of attempting to render a single marker on the map with MapQuickItem {}

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kai Nickel
                wrote on 12 Feb 2025, 14:17 last edited by
                #6

                I think you should not try to redefine the map instance that is already contained in MapView.
                Maybe this works:

                MapView {
                    id: myMapView
                    map.plugin: myPlugin
                    map.center: _map_container.coordinate
                    ...
                
                    MapQuickItem {
                        parent: myMapView.map
                        ...
                    }
                }
                
                
                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  Kory
                  wrote on 12 Feb 2025, 15:30 last edited by
                  #7

                  Thanks for the help, Kai, your way got rid of the grouped property error

                  image.png

                  1 Reply Last reply
                  0
                  • K Kory has marked this topic as solved on 12 Feb 2025, 15:31

                  2/7

                  11 Feb 2025, 16:05

                  5 unread
                  • Login

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