Results 1 to 2 of 2

Thread: Getting the pointer of a widget that emitted a signal in a slot

  1. #1
    Join Date
    Nov 2009
    Posts
    20
    Thanks
    6
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Getting the pointer of a widget that emitted a signal in a slot

    I have a slot:

    Qt Code:
    1. void myClass::on_eptErrorDSpin_valueChanged()
    2. {
    3. updateDesignMapQDoubleSpinBox(ui->eptErrorDSpin);
    4. }
    To copy to clipboard, switch view to plain text mode 

    for a QDoubleSpin widget whose objectName is eptErrorDSpin. The function updateDesignMapQDoubleSpinBox() expects a pointer to QDoubleSpin object, which is accomplished by using ui->eptErrorDSpin in the call. Out of curiosity, is there an "easier" way for me to obtain the pointer to eptErrorDSpin? For example, does a slot know anything of the caller that emitted the signal? Put another way, can a slot obtain the pointer of the widget that emitted the signal without explicitly having to specify it as I have done above or is there another, more general, approach that I can use?

    I was tinkering with the this pointer but don't know much about it.

    Thanks!

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Getting the pointer of a widget that emitted a signal in a slot

    take a look at QObject::sender.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following 2 users say thank you to spirit for this useful post:

    bred (31st October 2010), wconstan (7th December 2009)

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Replies: 4
    Last Post: 16th November 2008, 13:53
  4. Replies: 12
    Last Post: 18th September 2008, 15:04
  5. Replies: 2
    Last Post: 16th August 2007, 00:20

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.