[Qt-interest] Encapsulates question.
Alessandro Portale
alessandro.portale at nokia.com
Thu Aug 12 14:50:44 CEST 2010
On 8/12/2010 2:44 PM, ext phil prentice wrote:
> I have a class that encapsulates an array of custom objects i.e.
> class Fred
> {
> ...
> private:
> Mike mike[6]; // Custom widgets.
Instead of an array Mike[6] would use a QList<Mike*>. But that is
probably just a matter of taste.
> Now the index I wish to pass back is to identify which widget was selected.
> How best to do this?
That is exactly what QSignalMapper helps you with
http://doc.qt.nokia.com/4.6/qsignalmapper.html
The documentation has an example, which I reformulate for Fred and Mike,
below :)
Let Fred have one QSignalMapper member. If Mike is derived from
QPushButton, you connect the "SIGNAL(clicked())" of your Mikes to the
"SLOT(map())" of the QSignalMapper. And for each Mike also call
"QSignalMapper::setMapping()" with an individual int or QString.
Then connect the "SIGNAL(mapped(int/QString))" to Fred's handling
private slot.
Hope that helps,
Alessandro
More information about the Qt-interest-old
mailing list