Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Problem with sending a message from C++ Class to QML

    QML and Qt Quick
    3
    4
    266
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      msauer75 last edited by

      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

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        You need to add a notification signal to your property to let the system know that something was changed.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 3
        • Shrinidhi Upadhyaya
          Shrinidhi Upadhyaya last edited by

          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)
          

          Shrinidhi Upadhyaya.
          Upvote the answer(s) that helped you to solve the issue.

          1 Reply Last reply Reply Quote 1
          • M
            msauer75 last edited by

            Hi,

            thank you for your help. It works.

            BR
            martin

            1 Reply Last reply Reply Quote 0
            • First post
              Last post