Good day. I create a program for working with maps. The functional is still not quite simple and is being developed in Qt C ++. For the first display of the application, I use QQuickWidget to display the map. I liked QML very much, but I still struggle with the fact that I don’t fully understand how the interaction with js works, or rather the work with qml types.
I suggest to look at an example. The task is to put a few gps tracks on the map. Tracks are presented in GPX format (this is an ordinary xml. Example ). For the sake of experiment, I display them in a ListView.
Rectangle { id: rectmp width: 300 height: 300 XmlListModel { id: xmlModel source: "qrc:/gpx.gpx" query: "/gpx/trk/trkseg/trkpt" XmlRole { name: "lat"; query: "@lat/string()"} XmlRole { name: "lon"; query: "@lon/string()"} } ListView { width: 200; height: 300 model: xmlModel delegate: Text { text: "lat:" + lat + " lon:" + lon} } } At the output I get a list of coordinates. This is nice, but I can't figure out how elegantly to transfer this data to, for example, MapPolyLine?
With raw data in the documentation, it looks like this:
MapPolyline { id: track1 line.width: 3 line.color: 'green' path: [ { latitude: -27, longitude: 153.0 }, { latitude: -27, longitude: 154.1 }, { latitude: -28, longitude: 153.5 }, { latitude: -29, longitude: 153.5 } ] } where {latitude: -27, longitude: 153.0} is the type of coordinate. And how to bring in lat and lon values from xml I can’t figure it out.
With all this, in my case the number of tracks is different. How beautiful to make several PolyLine'ov and be able to continue to work with each of them? Again, each track involves working with a mouse, etc. Hence another question: how, similarly to C and JS, to make several objects of the same class in QML?