View Full Version : Replacement function for setOn QPushButton qt4?

9th April 2014, 01:37
Hi -

I used setOn in my qt3 code for setting a qpushbutton but am having a really hard time finding a way to do it in qt4. My code used to look like:


and I tried


However this causes a crash. GDB provides the following output:

#0 0x00007ffff76a706d in QAbstractButton::setChecked(bool) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4

Any help/advice is appreciated, as I can't seem to figure out what I am doing wrong.

9th April 2014, 01:48
The button needs to be set to allow toggling between checked and not checked: QAbstractButton::setCheckable(). Then QAbstractButton::setChecked() can be used to select one of the two states. This sort of button would often be a QToolButton rather than QPushButton.

9th April 2014, 10:18
As Chris said the equivalent to setOn(bool) is setChecked(bool).
setCheckable(bool) is the equivalent to setToggleButton(bool)