Good suggestion Chris.
Additional to that all buttons could connect to the same slot, QObject::sender() could be used to retrieve the button and then QObject:
roperty() could be used to extract the respective parameters.
Of, if all buttons have the same types of parameters but just different values, create a QToolButton subclass that has methods for those and cast QObject::sender() to that class and call the getters directly.
Another option would be to have separate receiver objects, one for each button. Each such instance would get its individual parameters upon construction, thus not needing any in the slot.
e.g.
class ButtonReceiver
: public QObject{
Q_OBJECT
public:
ButtonReceiver
( /* parameter */,
QObject *parent
= 0);
public slots:
void onButtonClicked();
};
class ButtonReceiver : public QObject
{
Q_OBJECT
public:
ButtonReceiver( /* parameter */, QObject *parent = 0);
public slots:
void onButtonClicked();
};
To copy to clipboard, switch view to plain text mode
QList<ButtonReceiver*> receiverList;
QList<ButtonReceiver*> receiverList;
To copy to clipboard, switch view to plain text mode
for (int i = 0; i < buttonList; ++i) {
connect(buttonList[i], SIGNAL(clicked()), receiverList[i], SLOT(onButtonClicked()));
}
for (int i = 0; i < buttonList; ++i) {
connect(buttonList[i], SIGNAL(clicked()), receiverList[i], SLOT(onButtonClicked()));
}
To copy to clipboard, switch view to plain text mode
Cheers,
_
Bookmarks