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. [SOLVED] Binding from javascript
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Binding from javascript

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 4.8k Views 1 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.
  • F Offline
    F Offline
    Fenix Voltres
    wrote on last edited by
    #1

    I create an item dynamically in js and my question is how can I set binding for that item?

    I tried following way, but to no avail:

    @var newLine = Qt.createQmlObject('import QtQuick 1.0; import Lines 1.0; Line {/.../}', rootScene)
    var newBinding = Qt.createQmlObject('import QtQuick 1.0; Binding {}', newLine)
    newBinding.target = newLine
    newBinding.property = "startingPoint"
    newBinding.value = Qt.point(node.x, node.y)@

    It SETS the value properly, but when node's position changes, my line doesn't update.

    What's the correct way, if this is not?

    When temptation brings me to my knees
    And I lay here drained of strength
    Show me kindness
    Show me beauty
    Show me truth

    1 Reply Last reply
    0
    • frankcyblogic.deF Offline
      frankcyblogic.deF Offline
      frankcyblogic.de
      wrote on last edited by
      #2

      You best establish the property bindings from QML. You know that you can instantiate your QML components simply by <code>componentId.createObject(<parent>)</code>?

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

        Property binding in JS will be available in Qt 4.7.4. See http://bugreports.qt.nokia.com/browse/QTBUG-14964

        1 Reply Last reply
        0
        • frankcyblogic.deF Offline
          frankcyblogic.deF Offline
          frankcyblogic.de
          wrote on last edited by
          #4

          I wasn't aware that I could do property bindings in JS.
          I'm impressed how QML/JS is evolving!

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Fenix Voltres
            wrote on last edited by
            #5

            [quote author="minimoog77" date="1302971106"]Property binding in JS will be available in Qt 4.7.4. See http://bugreports.qt.nokia.com/browse/QTBUG-14964[/quote]

            That's it, is there any chance for me to get current version of qt 4.7.4 (especially QtQuick 1.1) now?

            When temptation brings me to my knees
            And I lay here drained of strength
            Show me kindness
            Show me beauty
            Show me truth

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              Fenix, I think you can use Qt from "gitorious":https://qt.gitorious.org/qt in branch 4.7 (or maybe use master if you want even more experimental features).

              1 Reply Last reply
              0
              • frankcyblogic.deF Offline
                frankcyblogic.deF Offline
                frankcyblogic.de
                wrote on last edited by
                #7

                QtQuick 1.1 was just recently merged into the Qt 4.7 master. You always get the bleeding edge from the "staging area":https://qt.gitorious.org/+qt-developers/qt/staging (e.g. try branch "qtquick11-stable").

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  Fenix Voltres
                  wrote on last edited by
                  #8

                  Thank you, I compiled qtquick11-stable clone, but it didn't help; I found other workaround, though - if someone would have similar problem (with dynamically created bindings of dynamically created items):

                  *Firstly I created js stateful lib with declared two variables and assigned some objects to them (no matter what they were, just couldn't be nulls):

                  @var firstHook = someExistingObject1
                  var secondHook = someExistingObject2@

                  *Next I created a wrapper component with my custom Line element including mentioned lib with properties 'startingPoint' and 'endingPoint' binded to these variables:

                  @import QtQuick 1.0
                  import Lines 1.0
                  import "../../js/Curve.js" as CurveFunctions

                  Line {
                  id: line
                  penColor: "red"
                  penWidth: 2
                  startingPoint: Qt.point(CurveFunctions.firstHook.x, CurveFunctions.firstHook.y)
                  endingPoint: Qt.point(CurveFunctions.secondHook.x, CurveFunctions.secondHook.y)
                  }@

                  *Then I added two functions to my component which change values of those variables and simulated 1px move back and forth of previous binded objects, so properties could update properly:

                  @ function setFirst(first) {
                  CurveFunctions.firstHook = first
                  someExistingObject1.x += 1
                  someExistingObject1.x -= 1
                  }
                  function setSecond(second) {
                  CurveFunctions.secondHook = second
                  someExistingObject2.x += 1
                  someExistingObject2.x -= 1
                  }@

                  and it works. 'someExistingObjects' could have opacity 0.0, or be any accessible objects.
                  I'm not proud of it, but I wasn't able to figure out some other solution.

                  When temptation brings me to my knees
                  And I lay here drained of strength
                  Show me kindness
                  Show me beauty
                  Show me truth

                  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