I'm having trouble getting the setData() function of the QAbstractItemModel to work. Currently it looks like this :
bool ModelTestModel
::setData( const QModelIndex &index,
const QVariant
& value,
int role
) {
// qDebug( index );
qDebug( value.toString().toLatin1() );
qDebug
( QString::number( role
).
toLatin1() );
// if( role != Qt::CheckStateRole )
// return false;
ModelTestModelItem *item = static_cast<ModelTestModelItem*>( index.internalPointer() );
if( item->checkState() == Qt::Checked )
item->setCheckState( Qt::Unchecked );
else
item->setCheckState( Qt::Checked );
// emit dataChanged( index, index );
return true;
}
bool ModelTestModel::setData( const QModelIndex &index, const QVariant& value, int role )
{
// qDebug( index );
qDebug( value.toString().toLatin1() );
qDebug( QString::number( role ).toLatin1() );
// if( role != Qt::CheckStateRole )
// return false;
ModelTestModelItem *item = static_cast<ModelTestModelItem*>( index.internalPointer() );
if( item->checkState() == Qt::Checked )
item->setCheckState( Qt::Unchecked );
else
item->setCheckState( Qt::Checked );
// emit dataChanged( index, index );
return true;
}
To copy to clipboard, switch view to plain text mode
But the debug lines are not appearing in the console. It seems as though it is never getting called. Why would that be? Doesn't it automatically get called internally by QAbstractItemModel whenever you click on a QModelIndex?
Bookmarks