PDA

View Full Version : connect on a popup



mickey
12th April 2006, 15:34
Hi I have a button in mymainform connect to a SLOT (that open a popup) where inside this I set and show many checkBox; I'd like conenct every checkBox to another SLOT; but I'like avoid 8 connect (for each checkBox). I try this that compile and no mesage error, but the SLOT don't starts....


//constructor of myMainForm...
connect(popup, SIGNAL(clicked()), this, SLOT(setOption()));




void myMainForm::setting() {
c0 = new QCheckBox(vbox0);
c1 = new QCheckBox(vbox1);
........................................
popup->show();
}

vratojr
12th April 2006, 16:26
Hi,I haven't exactly understood the code you posted,however I tell you what I have understood.



//constructor of myMainForm...
connect(popup, SIGNAL(clicked()), this, SLOT(setOption()));

I suppose you want to use this single connection instead of the 8 connections for each button,is it right?
For what I know, it can't work because it's not the popup that emits the clicked() signal but are the buttons. If you want that your popup emits the clicked signal, you have to call it via a slot invoked by the clicked signal emitted from the buttons,:


//In the popup constructor
connect(buttonN,SIGNAL(clicked()),this,SLOT(emitcl icked())); //8 times,for each button

and then:


void Popup::emitclicked(){emit clicked();}


Another way is to organize the buttons inside an array,in this way you can spare lines of code;)


//inside Mainform
QVector<Button*> buttons;
for(int i=0;i<8;i++){
buttons[i]=new Button(...);
connect(buttons[i],SIGNAL(clicked()),this,SLOT(setOption()));

jacek
12th April 2006, 16:37
//In the popup constructor
connect(buttonN,SIGNAL(clicked()),this,SLOT(emitcl icked())); //8 times,for each button

and then:


void Popup::emitclicked(){emit clicked();}

This will work too:
connect( buttonN, SIGNAL( clicked() ), this, SIGNAL( clicked() ) );