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. How to change the value of QML Coordinate element at runtime?

How to change the value of QML Coordinate element at runtime?

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 4.2k 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.
  • J Offline
    J Offline
    JuanF
    wrote on last edited by
    #1

    Hi,

    I am developing an application which requirs to display different contents on QML Map element. I asked one question yesterday how to add/remove map objects at runtime, and it is not yet solved. I tried to do a workaround, and now I have got another problem.

    Is it possible to set the center of qml map or map object at runtime? The center of qml map and map object is a qml coordinate element.

    Using the following qml:

    @Map {
    id: map
    plugin : Plugin {
    name : "nokia"
    }
    anchors.fill: parent
    size.width: parent.width
    size.height: parent.height
    zoomLevel: t_data.zoomLevel
    center: Coordinate {latitude: 46.5; longitude: 6.6}//t_data.mapCenter

            onZoomLevelChanged: {
                console.log("Zoom changed")
            }
    
            MapCircle {
                 id: circle1
                 center: Coordinate {latitude: t_lati; longitude: t_lon} // {latitude: 46.5; longitude: 6.6}        
                 radius: t_data.radius
                 color: "yellow"
             }
    

    }@

    The mapCircle can not be displayed if I set the value of latitude & longtitude from C++. However, map.zoomLevel, and mapcircle.radius can get the value from C++.

    Did I do something wrong? How to control the value of QML Coordinate element from C++? I have checked the source code of QDeclarativeCoordinate and it has the latitude and longtitude as its properties, I don't understand why I can't expose data to it from C++?

    Thank you very much!

    Regards,
    Juan

    EDIT: added @ tag by vcsala

    1 Reply Last reply
    0
    • C Offline
      C Offline
      conny
      wrote on last edited by
      #2

      Hi!

      First of all the QML bindings for location stuff are currently (Qt Mobility 1.1.1) in a very sorry state. I've heard it should get better with QtM 1.2. I'm currently working around this by doing most map related things using C++.

      For your particular problem, I remember a snipped I used before moving to C++. Something like this worked for me:

      @
      function setPosition(lat, lon) {
      var coord = Qt.createQmlObject('import QtMobility.location 1.1; Coordinate{latitude:' + lat + ';longitude:' + lon + ';}', container, "coord");
      map.center = coord;
      }
      @

      This basically creates a new Coordinate object and sets it as center.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JuanF
        wrote on last edited by
        #3

        Hi Conny,

        I decide to move to the C++ side on map related issues as well... :-)

        Thank you!

        Juan

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dalaing
          wrote on last edited by
          #4

          Out of curiosity, are t_lati and t_lon defined anywhere? Without more information it's a) hard to help out and b) hard to check if this is fixed or needs fixing for the next release.

          I don't have any trouble modifying the center coordinate of circles from the QML side with the code in the master branch of git.

          David Laing
          Location API team
          Qt Mobility

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JuanF
            wrote on last edited by
            #5

            Hi,

            I use the Qt SDK 1.1 beta, not the sdk from MCL.

            I am now using the map widget from C++, but I will test how QML location plugin works when the 1.2 release is out.

            Thank you!

            Juan

            1 Reply Last reply
            0

            • Login

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