Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. QProperty; binding and onValueChanged
QtWS25 Last Chance

QProperty; binding and onValueChanged

Scheduled Pinned Locked Moved Unsolved Qt 6
6 Posts 2 Posters 1.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.
  • E Offline
    E Offline
    Eirik
    wrote on last edited by
    #1

    I'm not getting quite what I am expecting with QProperty bindings and onValueChanged(...)
    It seems that if I am tracking a property (i.e. QProperty::onValueChanged(...)) which is bound
    to another QProperty, and is also bound to by a third QProperty.

    My original code is much bigger then this, but I was able to reproduce my issue with the
    following code:

    #include <QProperty>
    #include <QDebug>
    
    int main( int, char** )
    {
       QProperty< bool > p{ true };
       QProperty< bool > pp{  [&](){ return p.value();  } };
       QProperty< bool > ppp{ [&](){ return pp.value(); } };
    
       auto ch1{ p.onValueChanged(   [&](){qDebug() << "p changed to:"   << p.value();   } ) };
       auto ch2{ pp.onValueChanged(  [&](){qDebug() << "pp changed to:"  << pp.value();  } ) };
       auto ch3{ ppp.onValueChanged( [&](){qDebug() << "ppp changed to:" << ppp.value(); } ) };
    
       qDebug() << p.value() << pp.value() << ppp.value();
    
       qDebug() << "\np.setValue( false );";
       p.setValue( false );
    
       qDebug() << p.value() << pp.value() << ppp.value();
    
       qDebug() << "\np.setValue( true );";
       p.setValue( true );
    
       qDebug() << p.value() << pp.value() << ppp.value();
    
       return 0;
    }
    

    The output I get is the following:

    true true true
    
    p.setValue( false );
    ppp changed to: false
    p changed to: false
    false false false
    
    p.setValue( true );
    ppp changed to: true
    p changed to: true
    true true true
    

    I.e. the value of all the QProperty objects are changing as expected, but
    the lamda for pp.onValueChanged is not executed. I.e. I whould have expected
    the following to be printed:

    true true true
    
    p.setValue( false );
    ppp changed to: false
    pp changed to: false
    p changed to: false
    false false false
    
    p.setValue( true );
    ppp changed to: true
    pp changed to: true
    p changed to: true
    true true true
    

    Are my expectations wrong or have I encountered a bug?

    My version of Qt I build from git, cloned today, using the dev branch, following the guide
    on the wiki, -developer-build.

    kshegunovK 1 Reply Last reply
    0
    • E Eirik

      I'm not getting quite what I am expecting with QProperty bindings and onValueChanged(...)
      It seems that if I am tracking a property (i.e. QProperty::onValueChanged(...)) which is bound
      to another QProperty, and is also bound to by a third QProperty.

      My original code is much bigger then this, but I was able to reproduce my issue with the
      following code:

      #include <QProperty>
      #include <QDebug>
      
      int main( int, char** )
      {
         QProperty< bool > p{ true };
         QProperty< bool > pp{  [&](){ return p.value();  } };
         QProperty< bool > ppp{ [&](){ return pp.value(); } };
      
         auto ch1{ p.onValueChanged(   [&](){qDebug() << "p changed to:"   << p.value();   } ) };
         auto ch2{ pp.onValueChanged(  [&](){qDebug() << "pp changed to:"  << pp.value();  } ) };
         auto ch3{ ppp.onValueChanged( [&](){qDebug() << "ppp changed to:" << ppp.value(); } ) };
      
         qDebug() << p.value() << pp.value() << ppp.value();
      
         qDebug() << "\np.setValue( false );";
         p.setValue( false );
      
         qDebug() << p.value() << pp.value() << ppp.value();
      
         qDebug() << "\np.setValue( true );";
         p.setValue( true );
      
         qDebug() << p.value() << pp.value() << ppp.value();
      
         return 0;
      }
      

      The output I get is the following:

      true true true
      
      p.setValue( false );
      ppp changed to: false
      p changed to: false
      false false false
      
      p.setValue( true );
      ppp changed to: true
      p changed to: true
      true true true
      

      I.e. the value of all the QProperty objects are changing as expected, but
      the lamda for pp.onValueChanged is not executed. I.e. I whould have expected
      the following to be printed:

      true true true
      
      p.setValue( false );
      ppp changed to: false
      pp changed to: false
      p changed to: false
      false false false
      
      p.setValue( true );
      ppp changed to: true
      pp changed to: true
      p changed to: true
      true true true
      

      Are my expectations wrong or have I encountered a bug?

      My version of Qt I build from git, cloned today, using the dev branch, following the guide
      on the wiki, -developer-build.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      What does this print?

       // ...
       qDebug() << p.value();
       qDebug() << pp.value();
       qDebug() << ppp.value();
       // ...
      

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Eirik
        wrote on last edited by Eirik
        #3

        prints the value of the properties, true or false. pp.value() and ppp.value() are always the same as p.value(), it is the fact that pp.onValueChanged(...) is never triggered I am wondering about.

        kshegunovK 1 Reply Last reply
        0
        • E Eirik

          prints the value of the properties, true or false. pp.value() and ppp.value() are always the same as p.value(), it is the fact that pp.onValueChanged(...) is never triggered I am wondering about.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Eirik said in QProperty; binding and onValueChanged:

          it is the fact that pp.onValueChanged(...) is never triggered I am wondering

          Yes, that's what I was interested in, the order of calls is something I had suspected, that's why I wanted to understand what you get as output in this case.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Eirik
            wrote on last edited by
            #5

            order of calls seems not to matter

            kshegunovK 1 Reply Last reply
            0
            • E Eirik

              order of calls seems not to matter

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #6

              @Eirik said in QProperty; binding and onValueChanged:

              order of calls seems not to matter

              It may be a bug, I suggest you post on the interest mailing list where this can get more exposure (you can reference this forum thread in your mail).

              Read and abide by the Qt Code of Conduct

              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