January 18, 2012

Arukas Arukas
Lab Rat
81 posts

Advance Signals and Slots

 

Hello-

If I have several widgets connected to a slot. I’d like the slot to know what widget triggered it by passing something like an integer. I looked in the help files and there was a mention of a signal mapper? Is that the best way and/or only way?

-Arukas

3 replies

January 19, 2012

joonhwan joonhwan
Lab Rat
94 posts

QSignalMapper itself is quite good to use in your considering design, though using QObject::sender() function to know the source of signal in your slot is quite handy.

 Signature 

joonhwan at gmail dot com

January 19, 2012

Andre Andre
Area 51 Engineer
6031 posts

Yes, QSignalMapper has been designed for this scenario. I prefer it over using QObject::sender(), because it makes it a bit clearer what happens IMHO. The method you create to actually do the work, will have the parameter identifying the widget already. Even if you call it directly, or through some other signal/slot connection, it will still work. The sender() approach does not have these saveguards, and you cannot judge from the function signature what will happen exactly. At the very least, you will need to check that sender() returns something sensible before trying to dereference it in your slot.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

January 19, 2012

Thanatos.jsse Thanatos.jsse
Ant Farmer
72 posts

Thanks…
It’s exactly what I’ve looking for.

BR,

 
  ‹‹ Ctrl+Wheel not working in QTextEdit and QPlainTextEdit      Kubuntu 10.11 and OpenGL ››

You must log in to post a reply. Not a member yet? Register here!