Unsolved Map in QQuickWidget not re-centering
-
Hello,
I am writing a small application which will relocate center of map each second. The values of longitude and latitude change, but the center of the map doesn't move. What am I doing wrong?
Initialized qml file at the start of form
@ ui->quickWidget->setSource(QUrl("qrc:/Map.qml")); @Propertys set from function triggered every second
@
void MainWindow::UpdateCoordinates()
{
...
QObject *map = ui->quickWidget->children().at(1);
map->setProperty("newLat", Lat);
map->setProperty("newLon", Lon);
}
@Map.qml
@
import QtQuick 2.0
import QtQuick.Window 2.0
import QtLocation 5.6
import QtPositioning 5.6Item{
id: itemControl
width: 512
height: 512
visible: trueproperty int zoomLevel
property real newLat: 45.5075693
property real newLon: 13.5824982Plugin {
id: mapPlugin
name: "esri"
}Map {
id:map
objectName: "map"
anchors.fill: parent
maximumZoomLevel: 15
minimumZoomLevel: 15
width: 512
height: 512
plugin: mapPlugin
center {
latitude: itemControl.newLat
longitude: itemControl.newLon
}
zoomLevel: itemControl.zoomLevel
}
}
@ -
@Tomzy97
Use rootObject function to return the Root Object of the QQuickWidget#include <QQuickItem> ... void MainWindow::UpdateCoordinates() { ... QObject *map = ui->quickWidget->rootObject(); if(map){ // avoid to access null pointer map->setProperty("newLat", Lat); map->setProperty("newLon", Lon); } }