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. passing coordinate value from c++ source file to qml file

passing coordinate value from c++ source file to qml file

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlqtquickmapofflineqtlocation
2 Posts 2 Posters 1.0k 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.
  • H Offline
    H Offline
    hem1
    wrote on 15 Oct 2018, 12:44 last edited by
    #1

    i am trying to update the coordinate values used in qml file for showing location on the map through c++ source file.
    My c++ source file
    @
    QQuickView *view = new QQuickView();
    view->setsource(Qurl::fromlocalfile(("filepath"));
    Qobject *item =view->rootObject();
    Item->setproperty("latitude",lat);
    Item->setProperty("longitude",lon);

    where lat and lon are the values which i want to pass to Qml file

    i have declared two properties named longitude and latitude for getting values from c++ file
    the map center is able to access these lat long values if they are chnaged from source file but marker is not updated according to the chnaged values, is there any better way to pass variables from Qt c++ to Qt Qml?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 15 Oct 2018, 19:01 last edited by
      #2

      Use a separate QObject-derived class and set it as context property.

      Other options:

      • https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
      • https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html

      (Z(:^

      1 Reply Last reply
      1

      1/2

      15 Oct 2018, 12:44

      • Login

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