I have a MapPolyline
object in my QtQuick Project. I need to change the path property from the C++ file, but I have no idea how to do that.
My qml - File:
MapPolyline {
id: mapline
objectName: "MapLine"
line.width: 5
line.color: "green"
path:
{[
{ latitude: 47.219791, longitude: 9.546032 },
{ latitude: 47.219657, longitude: 9.542508 },
{ latitude: 47.2194446, longitude: 9.5437876 }
]}
}
And now I want to change the content of the path property from the C++ file.
Thanks for the help!
Qt Location works okay from c++. You don't need to mess with any QJSValue stuff. Create a property in your QObject and return a QVariantList. Fill the QVariantList with QGeoCoordinate (the points in your line). In QML set the MapPolyline's path to the QObject QVariantList property. QML will automatically convert the QVariantList into a Javascript Array. QGeoCoordinates are qml coordinate type so the conversion is transparent. Any time you see a "list" type in qml, you can always return QVariantList from c++ or QVariantMap if you want to populate a Javascript Object (or create a Q_GADGET).
One thing that got me was that my QGeoCoordinates returned from c++ wasn't valid. If the QGeoCoordinates are invalid, the MapPolyLine fail to populate and will create a message: "Unsupported path type". Make sure QGeoCoordinate isValid() before adding it to the QVariantList.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With