⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

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)
        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)
        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.

  • Lifetime Qt Champion


    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)

  • Hi,

    thank you for your help. It works.


Log in to reply