To me what you want to accomplish will not make your code shorter as you still have to add all those slot names to the list, but here you go:
QList<const char*> slotList;
slotList << SLOT(slot1());
slotList << SLOT(slot2());
// ...
for(int i=0; i< listOfButtons.size();++i) {
connect(listOfButtons->at(i), SIGNAL(clicked()), this, slotList.at(i));
}
QList<const char*> slotList;
slotList << SLOT(slot1());
slotList << SLOT(slot2());
// ...
for(int i=0; i< listOfButtons.size();++i) {
connect(listOfButtons->at(i), SIGNAL(clicked()), this, slotList.at(i));
}
To copy to clipboard, switch view to plain text mode
Having said that I have to admit it all makes little sense to me. I'm assuming you are programming some kind of game (possibly a board game?) and you are using all those buttons for some kind of fields or pieces. In my opinion a much better approach would be to use Graphics View or at least to use a QSignalMapper and connect all your buttons to a single slot keyed by the button id.
Bookmarks