Connecting many SIGNALS to SLOTS
Hi
I have 100 Check-boxes (objects of QCheckBox) and 100 Line-edits (objects of QLineEdit) like this:
now I want to connect chb[0] to lndt[0] and chb[1] to lndt[1] and chb[2] to lndt[2] ,... and chb[99] to lndt[99]
One way is to write 100 times connects like:
Is there any other idea for using a for loop to do this.
Thanks a lot for any help
Re: Connecting many SIGNALS to SLOTS
Code:
for(int i=0; i<100; ++i)
QObject::connect(&chb
[i
],
SIGNAL(stateChanged
(int)),
&lndt
[i
],
SLOT(setText
(QString));
Ps: QCheckbox emits stateChanged signal not textChanged
Re: Connecting many SIGNALS to SLOTS
Of course you can use a for loop. This is basic C++. Just look at arguments 1 and 3 of your calls to QObject::connect(); there is an obvious pattern. If you know how to iterate over an array with a for loop, then you can surely figure out how do the same over two arrays in lockstep.
Re: Connecting many SIGNALS to SLOTS
thanks a lot Vikram.Saralaya
Code:
for(int i=0 ; i<10; i++)
{
lay.addWidget(lbl+i,i,0);
lay.addWidget(le+i,i,1);
}
wdg.show();