Hi I need to do connect below; is there a way? thanks
Code:
vector <QPushButton*> pb; pb.push_back(pushButton0); ................ connect(pb[i], SIGNAL(clicked()), this, SLOT(mySlot(i)));
Printable View
Hi I need to do connect below; is there a way? thanks
Code:
vector <QPushButton*> pb; pb.push_back(pushButton0); ................ connect(pb[i], SIGNAL(clicked()), this, SLOT(mySlot(i)));
Use QSignalMapper. You must register your QObject using QSignalMapper::setMapping() and connect it to QSignalMapper::map() slot. Then you have to connect the mapper to mySlot().
Either you will need to subclass QPushButton and reimplement keyEvents and mouseEvents.
Or you will need to have separate slots for each button like this.
Code:
vector <QPushButton*> pb; pb.push_back(pushButton0); pb.push_back(pushButton1); .......................... connect(pushButton0, SIGNAL(clicked()), this, SLOT(butto0Slot())); connect(pushButton1, SIGNAL(clicked()), this, SLOT(butto1Slot()));
Subclass QPushButton class and define an overloaded clicked signal.
Code:
signals: void clicked(int);
and a private slot
Code:
void reEmitClicked();
Now in the constructor connect the above two
Code:
connect(this, SIGNAL(clicked()), this, SLOT(reEmitClicked()));
Now in the defination of reEmitClicked(), emit your overloaded clicked signal.
Code:
emit clicked(i);
Now use this overloaded clicked signal, instead of the previous one.
Note: Keep i as a member or property of your class which you can pass through th ctor.