Send variable value from .cpp to .qml
-
Hello, I am collecting information from a gps (longitude and latitude) without problems. I represent this information in an lcdNumber, but I also want to send it to a .qml file to represent it in a map. After some tests I have not succeeded. Is there any simple way to do this? Do you have information about it?
I am new to using qt and qml.
Best regards
-
Can you show what your .pro file looks like ?
-
one way to do it as follows:
m_qmlAppEngine->rootContext()->setContextProperty( "lcdNumber", new lcdNumber() /* your class instance*/);
define the properties with signal for example longitudeChanged() in lcdNumber and you can use lcdNumber in any qml file -
Thanks to all, finally including in the .cpp,
connect(this, SIGNAL(<function_name>(QVariant)), obj, SLOT(<function_name>(QVariant)));works.
I have put the headers in the .h and defined the operation in the .qml.
Thank you!
@d4n1 said in Send variable value from .cpp to .qml:
connect(this, SIGNAL(<function_name>(QVariant)), obj, SLOT(<function_name>(QVariant)));
Just a suggestion: you should switch to Qt5 connect syntax. It has one important advantage: if you do something wrong you will get compiler error during the build instead of a warning during application runtime.