Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem with sending a message from C++ Class to QML

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 433 Views
  • 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 Offline
    M Offline
    msauer75
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      3
      • Shrinidhi UpadhyayaS Offline
        Shrinidhi UpadhyayaS Offline
        Shrinidhi Upadhyaya
        wrote on last edited by
        #3

        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
        1
        • M Offline
          M Offline
          msauer75
          wrote on last edited by
          #4

          Hi,

          thank you for your help. It works.

          BR
          martin

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved