Я строю mapPolyline, используя классы QGeopath и Pathcontroller из c ++. Теперь я хочу очистить эту картуPolyline. Я использую функцию clearPath () из класса Qgeopath и вызывал ее при нажатии кнопки. Как очистить путь из c ++ / qt. Я пробовал этот код
pathcontroller.h
class PathController: public QObject{
Q_OBJECT
Q_PROPERTY(QGeoPath geopath READ geoPath WRITE setGeoPath NOTIFY geopathChanged)
public:
PathController(QObject *parent = 0) : QObject(parent) {}
QGeoPath geoPath() const {
return mGeoPath;
}
void setGeoPath(const QGeoPath &geoPath) {
if(geoPath != mGeoPath) {
mGeoPath = geoPath;
emit geopathChanged();
}
}
Q_INVOKABLE void clearPath(){
mGeoPath.clearPath();
}
signals:
void geopathChanged();
private:
QGeoPath mGeoPath;
};
main.cpp
int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
QGeoPath path;
// path.addCoordinate(QGeoCoordinate(55.006355, 92.860984));
path.addCoordinate(QGeoCoordinate(55.1, 93.4567));
path.addCoordinate(QGeoCoordinate(56.1, 92.777));
PathController controller;
controller.setGeoPath(path);
// path.clearPath();
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("pathController", &controller);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
main.qml
Window {
visible: true
width: 640
height: 480
Plugin{
id: osmMapPlugin
name: "here"
PluginParameter { name: "here.app_id"; value: "oBB4FivcP23m2UZQCj8K"
}
PluginParameter { name: "here.token"; value: "P-D8XRRGeVt0YphUuOImeA"
}
}
Map {
anchors.fill: parent
plugin: osmMapPlugin
center: QtPositioning.coordinate(56.006355, 92.860984)
zoomLevel: 10
MapPolyline {
id: pl
line.width: 10
line.color: 'green'
}
Button {
id: button
x: 78
y: 117
text: qsTr("clear")
onClicked: {
pathController.clearPath();
}
}
}
function loadPath(){
var lines = []
for(var i=0; i < pathController.geopath.size(); i++){
lines[i] = pathController.geopath.coordinateAt(i)
}
return lines;
}
Connections{
target: pathController
onGeopathChanged: pl.path = loadPath()
}
Component.onCompleted: pl.path = loadPath()
}
Тем не менее, я получаю mapPolyline на карте. MapPolylines не очищают. Вопрос - как очистить Mappolylines