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. QML property binding is not getting refeshed with values set in C++

QML property binding is not getting refeshed with values set in C++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 254 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
    Mamatha
    wrote on last edited by
    #1

    Hi All,
    We are facing the issue in the QML integration with C++. The value set using set method in C++ is not being retrieved in QML. It always shows the wrong value. Please suggest how to retrieve the value in QML using property binding.

    ODБOïO KroMignonK 2 Replies Last reply
    0
    • M Mamatha

      Hi All,
      We are facing the issue in the QML integration with C++. The value set using set method in C++ is not being retrieved in QML. It always shows the wrong value. Please suggest how to retrieve the value in QML using property binding.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @Mamatha hi
      Qt QML -CPP integration-overview

      1 Reply Last reply
      0
      • M Mamatha

        Hi All,
        We are facing the issue in the QML integration with C++. The value set using set method in C++ is not being retrieved in QML. It always shows the wrong value. Please suggest how to retrieve the value in QML using property binding.

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @Mamatha Hi @Mamatha, you have to give more information about the way you are updating the value on C++ side and how you access the value on QML side.

        The standart/normal way to do is to define a property on C++ side, like this:

        class MyObject: public QObject
        {
            Q_OBJECT
        
            PROPERTY(QString myMessage GET getMyMessage NOTIFY myMessageChanged)
        
        public
            MyObject(QObject *parent = 0): QObject(parent), m_myMessage(QString()) {}
        
            QString getMyMessage() const { return m_myMessage }
            void updateMessage(const QString &message)
            {
                if(message != m_myMessage)
                {
                    m_myMessage = message;
                    emit myMessageChanged(message);
                }
            }
        
        public slots:
        
        signals:
             void myMessageChanged(const QString &message);
        
        private:
             QString m_myMessage;
        };
        

        Then on QML side, supposing you have exposed a variable called cppObject:

        Label {
        ...
            text: cppObject.myMessage 
        }
        

        That's it!

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        1

        • Login

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