QTableWidget QCheckbox extract values iteration
-
The values of the table are save using QSettings, ans once the program starts, the values are loaded into the table in this way (just the first row)::
void StatusConfigPage::setStatusTable(){ // Set Checkbox QSettings statusSettings("Rasper", "Interface"); statusSettings.beginReadArray("status"); for (int dataIndex = 0; dataIndex < dataClassArrayLength; dataIndex++){ statusSettings.setArrayIndex(dataIndex); QTableWidgetItem *item = new QTableWidgetItem(); item->data(Qt::CheckStateRole); statusTable->setItem(0, dataIndex, item); bool valueTemp; valueTemp = statusSettings.value("cellValue").toBool(); if(valueTemp){ item->setCheckState(Qt::Checked); } else { item->setCheckState(Qt::Unchecked); } }After manipulating the values of the QCheckboxes, the ones of the first row set on statusTable are intended to be store in this way:
void StatusConfigPage::updateSettings(){ QSettings statusSettings("Rasper", "Interface"); statusSettings.beginWriteArray("status"); for (int dataIndex = 0; dataIndex < dataClassArrayLength; dataIndex++) { statusSettings.setArrayIndex(dataIndex); bool valueTemp; QTableWidgetItem *item = statusTable->itemAt(0,dataIndex); if(item->checkState()==Qt::Checked){ valueTemp = true; } else { valueTemp = false; } statusSettings.setValue("cellValue", valueTemp); } statusSettings.endArray(); }I don't know exactly where or why, probably trying to save them (in updateSettings()), it is taking the value of the first element (statusTable->itemAt(0,dataIndex))) and saving it for the rest of the elements.
Thanks in advance!