How to pass double from Qt c++ code to QML code? -


i have code in qt

int main(int argc, char *argv[])  {     qguiapplication app(argc,argv);        qquickview view;        qurl q(qstringliteral("qml:///places_map.qml"));        view.setsource(qurl(qstringliteral("qrc:///places_map.qml")));          //i've tried init qml properties        qobject *object = view.rootobject();          object->setproperty("latitude", 48.4656371);          object->setproperty("longitude", 31.04900455);           qquickitem *item = view.rootobject();         item->setproperty("device_latitude", 48.4656371);         item->setproperty("device_longitude", 35.04900455); } 

and qml file:

import qtquick 2.0 import qtpositioning 5.5 import qtlocation 5.6  rectangle {     width: 720     height: 480      property double latitude:  0     property double longitude: 0     property double device_latitude: 0 //48.4656371     property double device_longitude: 0 //35.54900455      property variant location: qtpositioning.coordinate(latitude, longitude)     property variant devicelocation: qtpositioning.coordinate(device_latitude, device_longitude)      plugin {         id: myplugin         name: "osm"     }     placesearchmodel {            id: searchmodel             plugin: myplugin             searchterm: "pizza"            searcharea: qtpositioning.circle(devicelocation)             component.oncompleted: update()        }     map {         id: map         anchors.fill: parent         plugin: myplugin;         center: location         zoomlevel: 13          mapitemview {             model: searchmodel             delegate: mapquickitem {                 coordinate: devicelocation //qtpositioning.coordinate(device_latitude, device_longitude)                  anchorpoint.x: image.width * 0.5                 anchorpoint.y: image.height                  sourceitem: column {                     image { id: image; source: "marker.png" }                     text { text: title; font.bold: true }                 }             }         }     } } 

in qml code properties double latitude , longitude set view on map map shows place latitude = 0 , longtitude = 0

if set correct coordinates in qml code works how can init value c++ code map show city ?

using q_property better. exposing attributes of c++

i have working this:

main.cpp

#include <qguiapplication> #include <qqmlapplicationengine> #include <qquickitem> #include <qquickview>  int main(int argc, char *argv[]) {     qguiapplication app(argc, argv);      qquickview view;     view.setsource(qurl(qstringliteral("qrc:/main.qml")));      qquickitem *item = view.rootobject();     item->setproperty("number", 22.002);     view.show();     return app.exec(); } 

main.qml

import qtquick 2.4 import qtquick.window 2.2  rectangle{     visible: true     width: 640     height: 480     property double number : 0      text {         id: textedit         text: number         verticalalignment: text.alignvcenter         anchors.top: parent.top         anchors.horizontalcenter: parent.horizontalcenter         anchors.topmargin: 20     } } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -