Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. In qml, How can i get signal sender from slot/function?
Forum Updated to NodeBB v4.3 + New Features

In qml, How can i get signal sender from slot/function?

Scheduled Pinned Locked Moved Mobile and Embedded
11 Posts 5 Posters 13.1k 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.
  • N Offline
    N Offline
    nan3113
    wrote on last edited by
    #1

    In qml, How can i get signal sender from slot/function?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      In QML, AFAIK, you cannot. In C++, you might use the sender() method.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        billouparis
        wrote on last edited by
        #3

        I'm looking for the exact same mechanism. I dynamically created objects stored in a javascript list, they all send signals, calling the same function in my QML parent component. how can i know which dynamic object is sending a signal at run time? i would like to get a reference to the dynamic object that is actually sending the signal.
        Thank you for your help!
        Bill

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          What I use in my project is to send an index together with the signal (as one of signal's parameters). Then in the slot, it look for object with that index and voila - I know who sent it ;) Not a perfect solution, but works.

          (Z(:^

          1 Reply Last reply
          0
          • B Offline
            B Offline
            billouparis
            wrote on last edited by
            #5

            I can not rely on index, because I actually destroy some objects and then the index of the remaining object in my qml objects list are no longer valid. All index get shifted.
            Wonder if i can simply expose my viewer to QML world and call the sender() function.
            Do the qdeclarativeview inherits this sender() method?

            Bill

            [Moderator note: Deleted duplicate post in thread -- mlong]

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Most probably. sender() is declared in QObject, so most Qt classes have it.

              (Z(:^

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="sierdzio" date="1347991080"]Most probably. sender() is declared in QObject, so most Qt classes have it.[/quote]

                True, but I don't think you have access to that from the QML side of things. Wasn't that the whole point of the discussion?

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  Yeah, I somehow misunderstood billouparis's last statement. Although actually, hm. Maybe it could work? If you exposed ::sender() from C++? I try to avoid using sender() in my code, but maybe internal handling by moc would allow that. Could be a bit unreliable, but might work. I think I'll try to make some test app tomorrow, if time allows.

                  (Z(:^

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    vishu
                    wrote on last edited by
                    #9

                    hi.. @slerdzlo

                    please can you send your example code of sending index together with the signal please...

                    1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #10

                      Code of my project has evolved much since then, but here you go with an example: "link":https://github.com/sierdzio/closecombatfree/blob/master/src/qmlBase/ccfqmlbasescenario.cpp#L216.

                      (Z(:^

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        vishu
                        wrote on last edited by
                        #11

                        Thanku @slerdzlo.. Thanku very much

                        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