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. QQmlPropertyMap how to notify QML of updates
Forum Updated to NodeBB v4.3 + New Features

QQmlPropertyMap how to notify QML of updates

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
18 Posts 4 Posters 1.4k 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1
    This post is deleted!
    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @SPlatten said in QQmlPropertyMap how to notify QML of updates:

      QQmlPropertyMap

      QQmlPropertyMap does the binding.
      The binding is dynamic - whenever a key's value is updated, anything bound to that key will be updated as well.

      To detect value changes made in the UI layer you can connect to the valueChanged() signal. However, note that valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.

      SPlattenS 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD

        @SPlatten said in QQmlPropertyMap how to notify QML of updates:

        QQmlPropertyMap

        QQmlPropertyMap does the binding.
        The binding is dynamic - whenever a key's value is updated, anything bound to that key will be updated as well.

        To detect value changes made in the UI layer you can connect to the valueChanged() signal. However, note that valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.

        SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3
        This post is deleted!
        JoeCFDJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          This post is deleted!

          JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by JoeCFD
          #4

          @SPlatten https://doc.qt.io/qt-5.15/qqmlpropertymap.html
          connect the signal
          void valueChanged(const QString &key, const QVariant &value)
          in your qml and then check if the key is equal to your variable name. If yes, you know it is changed. No timestamp is needed.

          SPlattenS 1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            @SPlatten https://doc.qt.io/qt-5.15/qqmlpropertymap.html
            connect the signal
            void valueChanged(const QString &key, const QVariant &value)
            in your qml and then check if the key is equal to your variable name. If yes, you know it is changed. No timestamp is needed.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            @JoeCFD , the timestamp is needed so I can work out how old since the last update, if the time elapsed is greater than a specified period then the data is stale.

            JoeCFDJ 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @JoeCFD , the timestamp is needed so I can work out how old since the last update, if the time elapsed is greater than a specified period then the data is stale.

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by
              #6

              @SPlatten If it is needed, a query to current time in the connection code will do it.

              SPlattenS 1 Reply Last reply
              0
              • JoeCFDJ JoeCFD

                @SPlatten If it is needed, a query to current time in the connection code will do it.

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #7

                @JoeCFD The documentation for valueChanged says: Note: valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.

                JoeCFDJ 1 Reply Last reply
                0
                • SPlattenS SPlatten

                  @JoeCFD The documentation for valueChanged says: Note: valueChanged() is NOT emitted when changes are made by calling insert() or clear() - it is only emitted when a value is updated from QML.

                  JoeCFDJ Offline
                  JoeCFDJ Offline
                  JoeCFD
                  wrote on last edited by
                  #8

                  @SPlatten Do not calling insert() mean binding or clear() mean release binding? It makes sense that the value is not changed.

                  SPlattenS 1 Reply Last reply
                  0
                  • JoeCFDJ JoeCFD

                    @SPlatten Do not calling insert() mean binding or clear() mean release binding? It makes sense that the value is not changed.

                    SPlattenS Offline
                    SPlattenS Offline
                    SPlatten
                    wrote on last edited by
                    #9

                    @JoeCFD , this is a project that already exists, I am adding functionality to it.

                    JoeCFDJ 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      @JoeCFD , this is a project that already exists, I am adding functionality to it.

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by
                      #10

                      @SPlatten Read the example:
                      https://doc.qt.io/qt-5.15/qqmlpropertymap.html

                      QQmlPropertyMap ownerData;
                      ownerData.insert("name", QVariant(QString("John Smith")));  ==> will not trigger valueChanged, sort of like initialization
                      ownerData.insert("phone", QVariant(QString("555-5555")));
                      

                      write a small program to test it.

                      SPlattenS 1 Reply Last reply
                      0
                      • JoeCFDJ JoeCFD

                        @SPlatten Read the example:
                        https://doc.qt.io/qt-5.15/qqmlpropertymap.html

                        QQmlPropertyMap ownerData;
                        ownerData.insert("name", QVariant(QString("John Smith")));  ==> will not trigger valueChanged, sort of like initialization
                        ownerData.insert("phone", QVariant(QString("555-5555")));
                        

                        write a small program to test it.

                        SPlattenS Offline
                        SPlattenS Offline
                        SPlatten
                        wrote on last edited by SPlatten
                        #11

                        @JoeCFD , is it only the initial insert of an item that does not trigger the valueChanged signal ?

                        I will try this out tomorrow, thank you.

                        JoeCFDJ 1 Reply Last reply
                        0
                        • SPlattenS SPlatten

                          @JoeCFD , is it only the initial insert of an item that does not trigger the valueChanged signal ?

                          I will try this out tomorrow, thank you.

                          JoeCFDJ Offline
                          JoeCFDJ Offline
                          JoeCFD
                          wrote on last edited by
                          #12

                          @SPlatten the doc says clear() does not as well.

                          SPlattenS 1 Reply Last reply
                          0
                          • JoeCFDJ JoeCFD

                            @SPlatten the doc says clear() does not as well.

                            SPlattenS Offline
                            SPlattenS Offline
                            SPlatten
                            wrote on last edited by SPlatten
                            #13
                            This post is deleted!
                            JoeCFDJ B 2 Replies Last reply
                            0
                            • SPlattenS SPlatten

                              This post is deleted!

                              JoeCFDJ Offline
                              JoeCFDJ Offline
                              JoeCFD
                              wrote on last edited by
                              #14

                              @SPlatten In QML I guess you use id for connections.

                              1 Reply Last reply
                              0
                              • SPlattenS SPlatten

                                This post is deleted!

                                B Offline
                                B Offline
                                Bob64
                                wrote on last edited by
                                #15

                                @SPlatten I haven't followed this whole thread so apologies if I have missed something, but but regarding your most recent question, could you set your QQmlPropertyMap as a context property in your C++ back end? You would then be able in QML to use the name that you registered the context property as.

                                1 Reply Last reply
                                1
                                • D Offline
                                  D Offline
                                  Drooke
                                  wrote on last edited by
                                  #16

                                  Might be able to try:
                                  Item{
                                  Property var myData: backendQqmlPropertyMap.name
                                  OnMyDataChanged{
                                  // Doathing
                                  }
                                  }

                                  Sorry for formatting, on a phone currently!

                                  1 Reply Last reply
                                  1
                                  • SPlattenS Offline
                                    SPlattenS Offline
                                    SPlatten
                                    wrote on last edited by
                                    #17
                                    This post is deleted!
                                    SPlattenS 1 Reply Last reply
                                    0
                                    • SPlattenS SPlatten

                                      This post is deleted!

                                      SPlattenS Offline
                                      SPlattenS Offline
                                      SPlatten
                                      wrote on last edited by SPlatten
                                      #18
                                      This post is deleted!
                                      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