Question

I know you can do it when you have access to the QStandardItemModel but using combobox->model() returns a QAbstractItemModel which doesn't have the item(int row, int col) accessor. I've tried working with QAbstractItemModel::itemData(QModelIndex) but can't get it to work as I require.

I just need to get the CheckState of the items, if(item.checkState() == Qt::Checked) etc...

Edit: I have this code, can I cast it to a QStandardItem?

QModelIndex index(1, 0);
QVariant item = ui->SearchAssessmentCombo->model()->data(index, Qt::CheckStateRole);
Was it helpful?

Solution

You can't declare an index yourself, all indices are tied to a model. Internally, the data() function will determine that the index you gave in the parameter does not belong to the model and will return null values for everything.

You need to ask your model to give you a valid index before you can use it.

QModelIndex index = ui->SearchAssessmentCombo->model()->index(1,0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top