Results 1 to 4 of 4

Thread: How to find out whom invoked a slot?

  1. #1
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to find out whom invoked a slot?

    I have a slot for QSpinBox. This slot could be invoked by either user clicked on the spin box or programmatically changed the spin box value. If I run in debug mode, I could look at the stack trace to detect who invoked the method. Is there is way to find the invoker programmatically?

    Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to find out whom invoked a slot?

    There's sender() if thats any use to you? It only reports the object that emitted the signal though...

    I would expect however that the two events you state would be two different signals but both going to a single slot, therefore QSignalMapper would be more OO.

  3. #3
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to find out whom invoked a slot?

    Thanks squidge.

    sender() would work since it returns NULL when the slot was not activated by the signal.

    The QSignalMapper is also interesting.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find out whom invoked a slot?

    sender() should never be used in a method that may be invoked by means other than a signal-slot connection. You can't rely it will always be returning null in case of a direct call. If the call is made from a method invoked as a slot, sender() will probably contain the object that called the original slot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 15
    Last Post: 11th December 2012, 21:10
  2. Replies: 2
    Last Post: 16th September 2010, 12:33
  3. Why Qt can not find a public slot?
    By Alex Snet in forum Qt Programming
    Replies: 13
    Last Post: 13th April 2009, 09:31
  4. Replies: 11
    Last Post: 27th June 2008, 19:54
  5. Replies: 1
    Last Post: 6th March 2007, 16:27

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.