Problem with sending a message from C++ Class to QML
-
Hi,
I want to send an error message from a slot to a message box in my QML view. In the class errorController I create a Q_PROPERTY
Q_PROPERTY(QString ui_errMsg READ getErrMsg) public: QString getErrMsg(void) {return errMsg;}
A private member of ErrorController is in my class masterController defined. So I defined a Q_PROPERTY in masterController
Q_PROPERTY(gc::error::errorController* ui_errorController READ geterrorController CONSTANT) public: gc::error::errorController* geterrorController() {return errorBox;}
The default content auf errMsg will be printed in the error box of my view
Item { Rectangle { anchors.fill: parent Image { width: parent.width height: parent.height source: Style.imageBackground } ErrorMessageBox { headerText: masterController.ui_errorController.ui_errMsg } } }
If the content in errMsg changes during the execution of the programme the content of the error box won't be changed. Can you tell me where I do the mistake?
Thank you for your help.
BR
martin -
Hi,
You need to add a notification signal to your property to let the system know that something was changed.
-
Hi @msauer75 , as @SGaist told,you need to add a notification signal telling that the value has changed.
For example:-
Q_PROPERTY(QString errMsg READ errMsg NOTIFY errMsgChanged)
and if you want WRITE property, i mean if you want to change the value from QML side then,
Q_PROPERTY(QString errMsg READ errMsg WRITE setErrMsg NOTIFY errMsgChanged)