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
Qt 6.11 is out! See what's new in the release blog

'this' pointer in QML

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 6.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.
  • I Offline
    I Offline
    imihajlov
    wrote on 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 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 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

        • Login

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