Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Map in QQuickWidget not re-centering

Map in QQuickWidget not re-centering

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 432 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tomzy97
    wrote on last edited by
    #1

    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.6

    Item{
    id: itemControl
    width: 512
    height: 512
    visible: true

    property int zoomLevel
    property real newLat: 45.5075693
    property real newLon: 13.5824982

    Plugin {
    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
    }
    }
    @

    1 Reply Last reply
    0
    • KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by KillerSmath
      #2

      @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);
          }
      }
      

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved