Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Missing "this" and "sender" pointers in Qml

    QML and Qt Quick
    4
    4
    3016
    Loading More Posts
    • 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
      ivoryz last edited by

      It seems like using an item's id is the only way to obtain a reference to the Item (without resorting to "parent.children"):

      @Item {
      id: myId
      MouseArea {
      ...
      onClicked: someParent.someSignal(myId)
      }
      }@

      If I have a selection of several Items that need to emit the same signal "someParent.someSignal", then inventing a new id for each item just for passing it to the signal looks a bit tedious.

      To "code less", it would be nice to have something similar to the "this" pointer used in C++:
      @
      onClicked: someParent.someSignal(this)
      @

      Also, there is no "sender" pointer that could be used in an Item that receives someSignal.

      I hope these features are planned in some future release...
      Btw, console.log(this) prints out: "[object global]" - what is that? I could not find it in the docs...

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        [quote author="ivoryZ" date="1354164599"]I hope these features are planned in some future release...[/quote]

        You can suggest a feature on JIRA and/ or Qt development mailing list. I think this is a valid point, I miss such a feature, too.

        In your example, you can probably use the mouse event in the signal:
        @
        onClicked: someParent.someSignal(mouse)
        @
        But that is just one small, corner case.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • C
          chrisadams last edited by

          See http://doc.qt.digia.com/qt/qdeclarativejavascript.html for information.
          It's not as simple as you'd think to support the "this" keyword in most JavaScript expressions, but please do file a suggestion if one doesn't already exist.

          Cheers,
          Chris.

          1 Reply Last reply Reply Quote 0
          • N
            NicolasNarvaez last edited by

            i think that on embeded functions in the declarative objects, it is so easy has adding a preparser that creates temporary and transparent id for the functions, so that we can use this in many functions, but execution performance is equal.

            Am i wrong or it is in fact this way easy for most of the cases?

            1 Reply Last reply Reply Quote 0
            • First post
              Last post