[Qt-interest] Connect checkbox states

Alexandre Beraud aberaud at infflux.com
Tue Jun 16 16:02:25 CEST 2009


Hi,

I don't know what you want to achieve exactly, but if the two checkboxes 
must always have the same state, then there is no point in having two of 
them. If you want to make them exclusive, take a look at QButtonGroup. 
In the worst case connect checkBox1 to a slot that blocks the signals 
from checkBox2, changes its state, and re-enables the signals 
(blockSignals() function of the QObject class).
I hope it helps.
Regards,

Alex


Christian Lackas a écrit :
> Hi Everybody,
>
> how can I connect the checkbox state changed signal to the respective
> setter slot of a second checkbox?
>
> I tried:
>
>     connect(checkBox1, SIGNAL(stateChanged(int)),
>             checkBox2, SLOT(setChecked(bool)));
>
> which is incompatible, 
>
>     connect(checkBox1, SIGNAL(stateChanged(int)),
>             checkBox2, SLOT(setChecked(int)));
>
> where setChecked(int) is no valid slot, and also
>
>     connect(checkBox1, SIGNAL(stateChanged(int)),
>             checkBox2, SLOT(setCheckState(Qt::Checked)));
>
> which also produces a
>
>     No such slot QCheckBox::setCheckState(Qt::CheckState)
>     (since no slot, just a plain function)
>
> Unfortunately, I cannot use toggled(bool)/toggle, since I also want to
> connect checkBox2 to checkBox1 (they should be linked; at least
> most of the time) and this then produces and endless loop of togglings
> (amongst other problems).
>
> Why is there no simple setChecked(int) or setCheckState(int) slot?
> Am I missing something?
>
> Christian
>
>   


-- 
BERAUD Alexandre
Ingénieur Développement

Infflux - Informatique & Flux
Tel: 01 49 57 92 00 - Fax : 01 49 57 92 01
Mail: aberaud at infflux.com
Visitez notre site :  www.infflux.com





More information about the Qt-interest-old mailing list