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. programatically change the function associated with a property change
Forum Updated to NodeBB v4.3 + New Features

programatically change the function associated with a property change

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 388 Views 3 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.
  • C Offline
    C Offline
    Cyrille de Brebisson
    wrote on last edited by
    #1

    Hello,

    I know how to use qt.bindings on a property, but here, I need to programmatically assign a function to a property change.

    I am trying to do:

        onSomeEvent: onVisibleChangedChanged= Qt.binding(function () { something() })
    

    But the qml system does not seem to like this and throws a
    qrc:/qml/main.qml:612: TypeError: Cannot assign to read-only property "visibleChanged"
    error.

    Any guidance on how to handle this?
    Thanks,
    Cyrille

    Pablo J. RoginaP 1 Reply Last reply
    0
    • C Cyrille de Brebisson

      Hello,

      I know how to use qt.bindings on a property, but here, I need to programmatically assign a function to a property change.

      I am trying to do:

          onSomeEvent: onVisibleChangedChanged= Qt.binding(function () { something() })
      

      But the qml system does not seem to like this and throws a
      qrc:/qml/main.qml:612: TypeError: Cannot assign to read-only property "visibleChanged"
      error.

      Any guidance on how to handle this?
      Thanks,
      Cyrille

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @cyrille-de-brebisson said in programatically change the function associated with a property change:

      I need to programmatically assign a function to a property change.

      What could be your use case?
      What is the condition you'll use to go with one function or the other?

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Cyrille de Brebisson
        wrote on last edited by
        #3

        Hello,

        I need to do something on the property change, but only after the application has fully loaded...
        so I am trying to set this "binding" in the component.onCompleted function...
        Of course, I could add a boolean property to the original component, and do the action onVisibleChanged only when said boolean is true, however, I was trying to use a different method.

        Cyrille

        1 Reply Last reply
        0
        • IntruderExcluderI Offline
          IntruderExcluderI Offline
          IntruderExcluder
          wrote on last edited by
          #4

          This isn't a good idea, but if you really want such behavior, here is some magic:

          ApplicationWindow {
              id: root
              visible: true
              width: 400
              height: 680
          
              property var func: function() {console.log("Hello!")}
          
              Button {
                  id: b1
                  text: "Test"
              }
          
              Button {
                  y: 50
                  text: "Magic"
                  onClicked: {
                      b1.clicked.disconnect(root.func);
                      b1.clicked.connect(function(){console.log("Cya!");});
                  }
              }
          
              Component.onCompleted: {
                  b1.clicked.connect(root.func);
              }
          }
          

          Hovewer, you cannot disconnect signals which are binded to signals (onClicked) for example, I think this is because they sorta anonimous.

          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