Set path of PolyLine from the c++ file
-
I am trying to change the path from c++, sending the list from the mainwindow. But it isn't working. Any help?
The error is "QML MapPolyline: Unsupported path type"mainwindow.h
signals: void setCenter(QVariant, QVariant); void addMarker(QVariant, QVariant); void setMarkers(QVariantList);
mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QQuickItem> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/map.qml"))); ui->quickWidget->show(); auto obj = ui->quickWidget->rootObject(); connect(this, SIGNAL(setCenter(QVariant, QVariant)), obj, SLOT(setCenter(QVariant,QVariant))); connect(this, SIGNAL(addMarker(QVariant, QVariant)), obj, SLOT(addMarker(QVariant,QVariant))); connect(this, SIGNAL(setMarkers(QVariantList)), obj, SLOT(setMarkers(QVariantList))); emit setCenter(-28, 153.3658); emit addMarker(-28, 153.3658); QVariantList coordinates; coordinates.append(-29); coordinates.append(153); coordinates.append(-27); coordinates.append(154); emit setMarkers(coordinates); } MainWindow::~MainWindow() { delete ui; }
map.qml
import QtQuick 2.0 import QtLocation 5.6 import QtPositioning 5.6 Rectangle { id: window property double oldLat: 27.6585 property double oldLng: 153.3658 property var coordinateList: [] property Component comMarker: mapMarker Plugin { id: mapPlugin name: "osm" } Map { id: mapView anchors.fill: parent plugin: mapPlugin center: QtPositioning.coordinate(oldLat, oldLng); zoomLevel: 3 MapPolyline { id: coordinatePath line.width: 2 line.color: 'blue' smooth: true opacity: 0.8 path: [coordinateList] } } Component { id: mapMarker MapQuickItem { id: markerImg anchorPoint.x: image.width/4 anchorPoint.y: image.height coordinate: position sourceItem: Image { id: image source: "http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_red.png" } } } function setMarkers (list) { coordinateList = list; } function setCenter(lat, lng) { mapView.pan(oldLat - lat, oldLng - lng) oldLat = lat oldLng = lng } function addMarker(lat, lng) { var item = comMarker.createObject(window, {coordinate: QtPositioning.coordinate(lat, lng)}) mapView.addMapItem(item) } }