PDA

View Full Version : prob on connect



mickey
1st July 2006, 11:28
Hi I need to do connect below; is there a way? thanks


vector <QPushButton*> pb;
pb.push_back(pushButton0);
................
connect(pb[i], SIGNAL(clicked()), this, SLOT(mySlot(i)));

jacek
1st July 2006, 14:49
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().

munna
1st July 2006, 14:54
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.



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()));

sumsin
4th July 2006, 08:28
Subclass QPushButton class and define an overloaded clicked signal.



signals:
void clicked(int);


and a private slot



void reEmitClicked();


Now in the constructor connect the above two



connect(this, SIGNAL(clicked()), this, SLOT(reEmitClicked()));


Now in the defination of reEmitClicked(), emit your overloaded clicked signal.



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.