Unsolved QButtonGroup object is returning the -1
-
Hi Guys,
I have 3 radio buttons on the designer and one of them is checked by default and I have grouped them in a GroupBox, the Object name is grpCourse.
I'm passing the grpCourse to QButtonGroup constructor to know the which radio button will be selected in the runtime.
but It is written in -1 value.
code:QButtonGroup *radCourse=new QButtonGroup(ui->grpCourse); int btnid=radCourse->checkedId(); QAbstractButton *selectedbtn=radCourse->button(btnid); QString textofbtn=selectedbtn->text();
I don't why, but there is no compilation error.
-
@thippu If you start your app and look at it is any button checked?
-
@thippu said in QButtonGroup object is returning the -1:
I don't why, but there is no compilation error.
What compilation error would you expect on which line, and why?
-
@JonB First line in the constructor, Because I was passing the GroupBox not the buttons
-
@jsulm Yes, default radio button
-
@thippu said in QButtonGroup object is returning the -1:
@JonB First line in the constructor, Because I was passing the GroupBox not the buttons
http://doc.qt.io/qt-5/qbuttongroup.html#QButtonGroup take a
QObject *
as parent.QGroupBox
is aQWidget
, and so it's aQObject
.