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. Missing "this" and "sender" pointers in Qml
QtWS25 Last Chance

Missing "this" and "sender" pointers in Qml

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 4 Posters 3.3k Views
  • 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
    ivoryz
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      [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
      0
      • C Offline
        C Offline
        chrisadams
        wrote on last edited by
        #3

        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
        0
        • N Offline
          N Offline
          NicolasNarvaez
          wrote on last edited by
          #4

          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
          0

          • Login

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