[Qt-interest] Connect checkbox states

Christian Lackas delta at lackas.net
Tue Jun 16 16:14:20 CEST 2009


* Alexandre Beraud <aberaud at infflux.com> [090616 16:02]:

Hi Alexandre

> 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 have a couple of the checkboxes (and a couple of other QWidgets) in
two dialogs, which can be linked together (which is how it is used in
most cases; however, for fine tuning, you can disable the link and
adjust the widgets individually).
It works with most other QWidgets, that allow to transfer the state via
signal/slot. Just for QCheckBox I can't get it to work, which I find
strange (since here it should be straight forward; so I wonder if I just
don't see it).

Christian

> > 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
> 
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 

-- 
Mädchen, schützt eure Unschuld! Eßt Knoblauch, Knoblauch, Knoblauch!
http://www.lackas.net/ Perl Delphi Linux MP3 Searchengines Domainchecker



More information about the Qt-interest-old mailing list