I create a QRadioButton array and tried to init it with six radioButtons. At the moment when i populate array with object i do not receive any warnings or errors. But when i try to see if radio button is check i get crash for all radio button , but not for first item from array.
Here is the code :
// rd is declared in .h as QRadioButton *rd[6];
for (int c=0,c<6,c++) {
rd[c] = new QRadioButton("name");
verticalBox->addWidget(rd[c]); // it's a layout
}
Then make cheking :
if (rd[0]->isChecked() == true)
qDebug()<<"checked";
else if (rd[1]->isChecked() == true)
qDebug()<<"checked";
else if (rd[2]->isChecked() == true)
qDebug()<<"checked";
else if (rd[3]->isChecked() == true)
qDebug()<<"checked";
else if (rd[4]->isChecked() == true)
qDebug()<<"checked";
else if (rd[5]->isChecked() == true)
qDebug()<<"checked";
Don’t know exactly what is causing your crash, but I suggest you to leverage C++ features and Qt containers instead of manipulating C style arrays. Try this:
The rest of your code should execute fine