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. 'this' pointer in QML
Forum Updated to NodeBB v4.3 + New Features

'this' pointer in QML

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 6.5k 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.
  • I Offline
    I Offline
    imihajlov
    wrote on 5 Apr 2013, 13:38 last edited by
    #1

    QML have parent for referencing parent element, but does it have this for referencing this element?
    For example (Button is an imaginary element that has 'clicked' signal and 'color' property):
    @Item {
    Row {
    Repeater {
    Button {
    onClicked: {
    setColor(this)
    }
    }
    }
    }
    function setColor(o) {
    o.color = "red";
    }
    }@

    1 Reply Last reply
    1
    • R Offline
      R Offline
      RaubTieR
      wrote on 5 Apr 2013, 14:10 last edited by
      #2

      I think it doesn't have 'this' (any kind of), you can "look for youself":http://qt.gitorious.org/qt/qtdeclarative/blobs/6492909d345681dbe54deecbb02307a96b977b6d/src/quick/items/qquickitem.h. I'd suggest using 'id' property.
      @Item {
      Row {
      Repeater {
      Button {
      id: myButton // now identifiable
      onClicked: {
      setColor(myButton) // use id
      }
      }
      }
      }
      function setColor(o) {
      o.color = "red";
      }
      }@

      1 Reply Last reply
      1
      • C Offline
        C Offline
        chrisadams
        wrote on 8 Apr 2013, 00:02 last edited by
        #3

        Actually, the keyword "this" has specific meaning defined in binding expressions, however is undefined in signal handlers and other dynamic functions. See http://qt-project.org/doc/qt-5.0/qtqml/qtqml-javascript-hostenvironment.html for more information.

        1 Reply Last reply
        2

        1/3

        5 Apr 2013, 13:38

        • Login

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