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 on change ?

QML property on change ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
21 Posts 8 Posters 7.7k Views 2 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.
  • D Drooke

    @SPlatten the (assumed) Qproperty is defined in the (vehicle.data) class generally with a type, getter, setter, and Signal. If you can find in your codebase where the Qproperty is defined you can piggyback off of that signal.

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

    @Drooke , this is the biggest problem I'm having the source is huge and I've searched many times for something that could explain how it is accessed, I can see nothing, "vehicle" exists in various places, "totalWaterDepth" also exists in several places, but there nothing obvious that explains the access of vehicle.data.totalWaterDepth.

    Kind Regards,
    Sy

    1 Reply Last reply
    0
    • SPlattenS SPlatten

      @freedbrt , doesn't the property type itself have any events that can be implemented ?

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

      @SPlatten totalWaterDepthChanged() is a signal and has to be defined by the coder. If there is no reaction for your change, that means totalWaterDepthChanged() signal does not exist. You can search for it with grep.

      1 Reply Last reply
      0
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #12

        Look for Q_PROPERTY macros:

        Q_PROPERTY(int ted READ ted WRITE setted NOTIFY tedChanged)
        

        Note: the NOTIFY signal can be named anything.

        C++ is a perfectly valid school of magic.

        JoeCFDJ 1 Reply Last reply
        1
        • fcarneyF fcarney

          Look for Q_PROPERTY macros:

          Q_PROPERTY(int ted READ ted WRITE setted NOTIFY tedChanged)
          

          Note: the NOTIFY signal can be named anything.

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

          @fcarney is right. The signal name can be anything. I normally use tedChanged in my app.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lemons
            wrote on last edited by
            #14

            Couldn't vehicle.data also be a struct with a Q_GADGET macro?
            → in this case there might only be a dataChanged signal, instead of a signal for each member of the struct

            SPlattenS 1 Reply Last reply
            0
            • L lemons

              Couldn't vehicle.data also be a struct with a Q_GADGET macro?
              → in this case there might only be a dataChanged signal, instead of a signal for each member of the struct

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

              @lemons , its not my code and I have no say on how it is or was coded.

              Kind Regards,
              Sy

              D 1 Reply Last reply
              0
              • SPlattenS SPlatten

                @lemons , its not my code and I have no say on how it is or was coded.

                D Offline
                D Offline
                Drooke
                wrote on last edited by
                #16

                @SPlatten try console.log(vehicle) and console.log(vehicle.data) in a component.oncompleted block. which may print out the classname / QObject type. This may point to the location of your code you're looking for.

                1 Reply Last reply
                0
                • GrecKoG Offline
                  GrecKoG Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on last edited by
                  #17

                  To answer the original question :

                  Is there a way to create an event handler for when a property changes ?

                  Something like:

                  property double waterDepth: vehicle.data.totalWaterDepth
                  onWaterDepthChanges: {
                     ...
                  }
                  

                  The corresponding change signal would be waterDepthChanged, with its handler being onWaterDepthChanged: ....

                  Scrolling through your past exchange would make me guess that vehicle has a property data which is a QQmlPropertyMap where the totalWaterDepth is eventually set. Doesn't a global search followed by some code unravelling give you any clues?

                  But why do you need a signal handler in the first place? It's generally a code smell and should be available when possible (moreso when it's not a boolean property).

                  SPlattenS 2 Replies Last reply
                  0
                  • GrecKoG GrecKo

                    To answer the original question :

                    Is there a way to create an event handler for when a property changes ?

                    Something like:

                    property double waterDepth: vehicle.data.totalWaterDepth
                    onWaterDepthChanges: {
                       ...
                    }
                    

                    The corresponding change signal would be waterDepthChanged, with its handler being onWaterDepthChanged: ....

                    Scrolling through your past exchange would make me guess that vehicle has a property data which is a QQmlPropertyMap where the totalWaterDepth is eventually set. Doesn't a global search followed by some code unravelling give you any clues?

                    But why do you need a signal handler in the first place? It's generally a code smell and should be available when possible (moreso when it's not a boolean property).

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

                    @GrecKo , I tried that and it doesn't work, I think because the primitive type double is not an object.

                    Kind Regards,
                    Sy

                    GrecKoG 1 Reply Last reply
                    0
                    • GrecKoG GrecKo

                      To answer the original question :

                      Is there a way to create an event handler for when a property changes ?

                      Something like:

                      property double waterDepth: vehicle.data.totalWaterDepth
                      onWaterDepthChanges: {
                         ...
                      }
                      

                      The corresponding change signal would be waterDepthChanged, with its handler being onWaterDepthChanged: ....

                      Scrolling through your past exchange would make me guess that vehicle has a property data which is a QQmlPropertyMap where the totalWaterDepth is eventually set. Doesn't a global search followed by some code unravelling give you any clues?

                      But why do you need a signal handler in the first place? It's generally a code smell and should be available when possible (moreso when it's not a boolean property).

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

                      @GrecKo said in QML property on change ?:

                      QQmlPropertyMap

                      Thank you, you have given me a helpful hint in that I have now located:

                      Q_PROPERTY (QQmlPropertyMap *data READ data CONSTANT)
                      

                      Kind Regards,
                      Sy

                      1 Reply Last reply
                      0
                      • SPlattenS SPlatten

                        @GrecKo , I tried that and it doesn't work, I think because the primitive type double is not an object.

                        GrecKoG Offline
                        GrecKoG Offline
                        GrecKo
                        Qt Champions 2018
                        wrote on last edited by
                        #20

                        @SPlatten said in QML property on change ?:

                        @GrecKo , I tried that and it doesn't work, I think because the primitive type double is not an object.

                        That doesn't prevent it from triggering change signals.

                        Maybe your vehicle or data is changed in C++ without emitting any NOTIFY signal? if totalWaterDepth is in a QQmlPropertyMap it shouldn't be able to be changed without emitting a signal so that leaves the other two.

                        How do you know the final value changes?

                        SPlattenS 1 Reply Last reply
                        0
                        • GrecKoG GrecKo

                          @SPlatten said in QML property on change ?:

                          @GrecKo , I tried that and it doesn't work, I think because the primitive type double is not an object.

                          That doesn't prevent it from triggering change signals.

                          Maybe your vehicle or data is changed in C++ without emitting any NOTIFY signal? if totalWaterDepth is in a QQmlPropertyMap it shouldn't be able to be changed without emitting a signal so that leaves the other two.

                          How do you know the final value changes?

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

                          @GrecKo , I see if update on the QML front end.

                          Kind Regards,
                          Sy

                          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