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. Sometimes QML property binding doesn't updates

Sometimes QML property binding doesn't updates

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
13 Posts 4 Posters 3.0k 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 Manta Ray

    I have the next code:

    property int maxCount: convert(isMaxUser ? user.maxUserCount : admin.maxAdminCount)
    
    Label{
    	text: maxCount.toString()
    }
    

    At all it works good, but sometimes maxCount value is stuck, it doesn't changes anymore. It occurs very seldom and I don't know how I can use property binding in the best way to avoid this strange behaviour.

    I've tried to update maxCount velue in this way:

    property int maxUser: user.maxUserCount
    property int maxAdmin: admin.maxAdminCount
    
    property int maxCount: convert(isMaxUser ? maxUser : maxAdmin)
    
    onMaxAdminChanged{
    	maxCount= convert(isMaxUser ? maxUser : maxAdmin)
    }
    
    onMaxUserChanged{
    	maxCount= convert(isMaxUser ? maxUser : maxAdmin)
    }
    

    But I think that this way is too complex.

    Can you advise me something to solve my issue in the best way?

    Thanks a lot!

    R Offline
    R Offline
    Roumed
    wrote on last edited by
    #2

    @Manta-Ray

    At first, just for debug you can do this:

    property int maxCount: {
        print("isMaxUser: " + isMaxUser)
        print("user.maxUserCount: " + user.maxUserCount)
        print("admin.maxAdminCount: " + admin.maxAdminCount)
        var res = convert(isMaxUser ? user.maxUserCount : admin.maxAdminCount);
        print("res: " + res)
        return res;
    }
    

    This will help you to catch a case of stuck.
    This is entry point to solve your problem.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Manta Ray
      wrote on last edited by
      #3

      Thanks a lot, I'll try this.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Viet
        wrote on last edited by
        #4

        Have you tried Qt.binding() ?
        Eg: Component.onCompleted: {
        maxCount = Qt.binding( function() { return convert(isMaxUser ? user.maxUserCount : admin.maxAdminCount) } )
        }

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Manta Ray
          wrote on last edited by Manta Ray
          #5

          I've found that sometimes (very seldom 1 from 50) binding to method doesn't work.
          I've separated property and method call in that way:

          property int value: isMaxUser ? user.maxUserCount : admin.maxAdminCount
          property int maxCount: convert(value)
          onValueChanged: {
              maxCount = convert(value)
          }
          

          I hope this issue won't reproduce anymore...

          R 1 Reply Last reply
          0
          • M Manta Ray

            I've found that sometimes (very seldom 1 from 50) binding to method doesn't work.
            I've separated property and method call in that way:

            property int value: isMaxUser ? user.maxUserCount : admin.maxAdminCount
            property int maxCount: convert(value)
            onValueChanged: {
                maxCount = convert(value)
            }
            

            I hope this issue won't reproduce anymore...

            R Offline
            R Offline
            Roumed
            wrote on last edited by Roumed
            #6

            @Manta-Ray
            Which binding doesn't work?
            Could you give us a trace logged code with logs?

            E 1 Reply Last reply
            0
            • R Roumed

              @Manta-Ray
              Which binding doesn't work?
              Could you give us a trace logged code with logs?

              E Offline
              E Offline
              Eeli K
              wrote on last edited by
              #7

              @Roumed said in Sometimes QML property binding doesn't updates:

              Could you give us a trace logged code with logs?

              Or at least the whole project/code and instructions how to try to reproduce the problem. This looks interesting if it really does happen without a bug in your code.

              1 Reply Last reply
              1
              • M Offline
                M Offline
                Manta Ray
                wrote on last edited by
                #8

                Sometimes this:

                property int maxCount: convert(isMaxUser ? user.maxUserCount : admin.maxAdminCount)
                

                doesn't work. I see the log message in backend before emit signal user.maxUserCountChanged, then I see that label doesn't changes and doesn't see log message in convert method. So I decided that sometimes, depends on CPU usage or count of processes in the system or something else this method doesn't call. It happens very-very seldom, maybe 1 from100 times.

                E 1 Reply Last reply
                0
                • M Manta Ray

                  Sometimes this:

                  property int maxCount: convert(isMaxUser ? user.maxUserCount : admin.maxAdminCount)
                  

                  doesn't work. I see the log message in backend before emit signal user.maxUserCountChanged, then I see that label doesn't changes and doesn't see log message in convert method. So I decided that sometimes, depends on CPU usage or count of processes in the system or something else this method doesn't call. It happens very-very seldom, maybe 1 from100 times.

                  E Offline
                  E Offline
                  Eeli K
                  wrote on last edited by
                  #9

                  @Manta-Ray What is convert() ?

                  M 1 Reply Last reply
                  0
                  • E Eeli K

                    @Manta-Ray What is convert() ?

                    M Offline
                    M Offline
                    Manta Ray
                    wrote on last edited by
                    #10

                    @Eeli-K This is the method which rounds values.
                    I can't show you the original code, but it looks like:

                    .cpp
                    if(...){
                        print("Max user count changed:  %d", maxUserCount);
                        emit maxUserCountChanges();
                    }
                    
                    .qml
                    property int maxCount: convert(isMaxUser ? user.maxUserCount : admin.maxAdminCount)
                    
                    onMaxCountChanged:{
                        console.log("Max count changed: ", maxCount)
                    }
                    
                    Label{
                    	text: maxCount.toString()
                    }
                    
                    function convert(int val){
                        console.log("Convert value: ", val)
                        .......
                    }
                    
                    

                    During work I see the next logs:
                    123.12 Max user count changed: 4

                    And never see:
                    Convert value: 4
                    or
                    Max count changed: 4

                    It works almost always but sometimes...

                    R 1 Reply Last reply
                    0
                    • M Manta Ray

                      @Eeli-K This is the method which rounds values.
                      I can't show you the original code, but it looks like:

                      .cpp
                      if(...){
                          print("Max user count changed:  %d", maxUserCount);
                          emit maxUserCountChanges();
                      }
                      
                      .qml
                      property int maxCount: convert(isMaxUser ? user.maxUserCount : admin.maxAdminCount)
                      
                      onMaxCountChanged:{
                          console.log("Max count changed: ", maxCount)
                      }
                      
                      Label{
                      	text: maxCount.toString()
                      }
                      
                      function convert(int val){
                          console.log("Convert value: ", val)
                          .......
                      }
                      
                      

                      During work I see the next logs:
                      123.12 Max user count changed: 4

                      And never see:
                      Convert value: 4
                      or
                      Max count changed: 4

                      It works almost always but sometimes...

                      R Offline
                      R Offline
                      Roumed
                      wrote on last edited by
                      #11

                      @Manta-Ray
                      We definitely need to know more about your environment.

                      M 1 Reply Last reply
                      0
                      • R Roumed

                        @Manta-Ray
                        We definitely need to know more about your environment.

                        M Offline
                        M Offline
                        Manta Ray
                        wrote on last edited by Manta Ray
                        #12

                        @Roumed Application is working on ubuntu 14.04. I don't have an information about hardware.

                        E 1 Reply Last reply
                        0
                        • M Manta Ray

                          @Roumed Application is working on ubuntu 14.04. I don't have an information about hardware.

                          E Offline
                          E Offline
                          Eeli K
                          wrote on last edited by
                          #13

                          @Manta-Ray
                          If this really is a bug in Qt, it's important. Could you at least create a project, as small as possible, which would produce the same problem? It's impossible to help, find the bug and fix it if you can't show exactly how it can be reproduced, especially when it's random. Also information about the hardware is necessary if it doesn't happen to others with their platform.

                          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