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. Override onPropertyChanged in inherited

Override onPropertyChanged in inherited

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 338 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.
  • D Offline
    D Offline
    dextermagnific
    wrote on last edited by
    #1

    Hi all,

    I have a specialized SpinBox in a .qml in which I implemented a default onValueModified:

    # MySpinBox.qml
    
    SpinBox {
    ...
      onValueModified: { print("modified in Base") }
    }
    

    Now I use this in my QML:

    MySpinBox  {
      onValueModified: { print("modified in inherited") }
    }
    

    My problem is that I get the two messages printed. I thought that "on property changed" will be overriden in the inherited class. This happens like this for functions.

    How can I manage so that only the code in the inherited implementation will be executed ?

    Thank you

    Pradeep P NP 1 Reply Last reply
    0
    • D dextermagnific

      Hi all,

      I have a specialized SpinBox in a .qml in which I implemented a default onValueModified:

      # MySpinBox.qml
      
      SpinBox {
      ...
        onValueModified: { print("modified in Base") }
      }
      

      Now I use this in my QML:

      MySpinBox  {
        onValueModified: { print("modified in inherited") }
      }
      

      My problem is that I get the two messages printed. I thought that "on property changed" will be overriden in the inherited class. This happens like this for functions.

      How can I manage so that only the code in the inherited implementation will be executed ?

      Thank you

      Pradeep P NP Offline
      Pradeep P NP Offline
      Pradeep P N
      wrote on last edited by Pradeep P N
      #2

      @dextermagnific said in Override onPropertyChanged in inherited:

      SpinBox

      • Can you please tell me why you want to call valueModified() signal from SpinBox { } when you can directly use it from MySpinBox { } ?

      To avoid your problem you can define your own signal and use it.

      MySpinBox.qml

      SpinBox {
          id: root
          
          signal valueChanged()
      
          onValueModified: {
              root.valueChanged();
          }
      }
      

      And in main.qml just use onValueChanged

          MySpinBox {
      
              onValueChanged: {
                  console.log("Value :: ", value)
              }
          }
      

      Pradeep Nimbalkar.
      Upvote the answer(s) that helped you to solve the issue...
      Keep code clean.

      1 Reply Last reply
      1

      • Login

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