How to connect in Qt signal and slot in dynamically added buttons to get in slot index of added button?
问题 I have list with pointers QPushButton: QList<QPushButton*> listButtons; In this code I am adding dynamically buttons listButtons.push_back(new QPushButton("Cancel", this)); connect(listButtons.last(), SIGNAL (clicked(listButtons.size)), this, SLOT(handleButton(int))); //this doesn't work How can I also save index of every button, so I can keep track, what button user clicked, because every button has to cancel specific task. I use C++98, so I can not use Lambda function 回答1: You have to use