PDA

View Full Version : connect and widget index



nowire75
25th November 2007, 16:23
Hi,

I need to connect a changed signal of a QSpinBox, QDoubleSpinBox, and a QLineEdit member of a QWidget array with a on_Change slot, but I need to transmit also the index of a QWidegt.
This code work fine (this for QSpinBox):


connect(widget[index], SIGNAL(valueChanged(const QString &)), this, SLOT(on_Changed()));

but I want to send also the index, like this:


connect(widget[index], SIGNAL(valueChanged(const QString &)), this, SLOT(on_Changed(const int &myindex)));


thanks

jpn
25th November 2007, 16:33
Hi, take a look at QSignalMapper:


QSignalMapper* mapper = new QSignalMapper(this);
...
connect(widget[index], SIGNAL(valueChanged(const QString &)), mapper, SLOT(map()));
mapper->setMapping(widget[index], index);
...
connect(mapper, SIGNAL(mapped(int)), this, SLOT(on_Changed(int)));