[Qt-interest] How To: pass extra data to object slots from menu action signals?

Andreas Pakulat apaku at gmx.de
Mon Feb 1 23:52:04 CET 2010


On 01.02.10 16:06:38, kent williams wrote:
> I found a way around this problem, but somehow it feels sneaky:
> 
> 1. Derive a new class from QAction, and add the data I need to this class.
> 2. Add my derived-from-QAction class to the QMenu after setting the member data.
> 3. In the action connected to my action, cast sender() to my derived
> type, and retrieve the needed data from it.

You don't need the derive-from part, you could simply use setData() with
a suitable QVariant (list, hash or QPair after using
Q_DECLARE_METATYPE(QPair)) and then fetch the data again in the slot
connected to the signal-mapper.

Andreas
-- 
Tomorrow, this will be part of the unchangeable past but fortunately,
it can still be changed today.



More information about the Qt-interest-old mailing list