Unsolved How to reload qml from cpp file?
-
Need to reload the total qml file from cpp file on some time interval.I can do it in qml using loader function.How to do using cpp file??
-
Hi,
Define a string type Qproperty in your cpp class and bind it to "source" property of Loader in QML.
Now you can change the source of that Loader by changing the QProperty value from cpp.eg:- /// CPP code
class XXXXX /// Register this class/object to QML using qmlRegisterType()/setConextProperty()
{
Q_OBJECT
...
Q_PROPERTY(QString sourcePath READ sourcePath NOTIFY sourcePathChanged) //// Bind this "sourcePath" property to QML.QString sourcePath() { return m_SourcePath }; signals: void sourcePathChanged(); /// Notify this signal when you change the source path from CPP private: QString m_SourcePath; /// Update this value and emit sourcePathChanged() signal from cpp to reload QML Loader.
}
/// QML code
Loader {
id: myLoader
source: XXXXX.sourcePath /// Bind the property to loader's source property.
}Hope this will help you.
Thanks,
Rajeesh Raveendran -
@RajeeshRaveendran
Thanks for the reply...In this I am not going to change the path of the qml file but going to change the entire content in the qml.Any Suggestions to solve this???