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++
Forum Updated to NodeBB v4.3 + New Features

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 258 Views 1 Watching
  • 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 21 Oct 2019, 09:29 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.

    O K 2 Replies Last reply 21 Oct 2019, 09:31
    0
    • M Mamatha
      21 Oct 2019, 09:29

      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.

      O Offline
      O Offline
      ODБOï
      wrote on 21 Oct 2019, 09:31 last edited by
      #2

      @Mamatha hi
      Qt QML -CPP integration-overview

      1 Reply Last reply
      0
      • M Mamatha
        21 Oct 2019, 09:29

        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.

        K Offline
        K Offline
        KroMignon
        wrote on 21 Oct 2019, 09:55 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

        3/3

        21 Oct 2019, 09:55

        • Login

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