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?


  • 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.

  • Yes, [[doc: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.

  • Thanks...
    It's exactly what I've looking for.


Log in to reply