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. How to assign property values temporarily without breaking existing binding in qml?
QtWS25 Last Chance

How to assign property values temporarily without breaking existing binding in qml?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmltextfieldbindingcancel
2 Posts 2 Posters 2.8k 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.
  • R Offline
    R Offline
    red.green
    wrote on last edited by red.green
    #1

    I have TextField whose text is bound with another value. However, when I press cancel of the virtual keyboard I want to revert its value and this value is stored in another variable. However, the following code breaks existing binding of TextField's text with the other value.

    Keys.onCancelPressed:
    {
          text = previousNumber
          focus = false
    }
    

    How do I make sure that the previous binding is kept intact?

    Thanks.

    sierdzioS 1 Reply Last reply
    0
    • R red.green

      I have TextField whose text is bound with another value. However, when I press cancel of the virtual keyboard I want to revert its value and this value is stored in another variable. However, the following code breaks existing binding of TextField's text with the other value.

      Keys.onCancelPressed:
      {
            text = previousNumber
            focus = false
      }
      

      How do I make sure that the previous binding is kept intact?

      Thanks.

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @red.green said in How to assign property values temporarily without breaking existing binding in qml?:

      How do I make sure that the previous binding is kept intact?

      Assigning a value breaks the binding - if it was not this way QML would be horribly broken ;-)

      There are a few ways around it, though. First, most obvious one - set the new value on the binding source. So if you have:

      Text {
        text: someProperty
      } 
      

      Assign your temporary value to someProperty. You can add some code that will manage it's temporary nature there (onPropertyChanged or better in some object that holds the value of that property).

      Another way is to set up the binding using Binding element, disable it when Cancel is pressed, then enable it again once your temporary situation changes.

      (Z(:^

      1 Reply Last reply
      2

      • Login

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