You should be doing this.
{
if (!index.isValid())
return;
const MyModel *model = qobject_cast<const MyModel*>(index.model());
...
if(model != 0)
QString first
= model
->data
(index, ItemRoles
::First).
toString();
// <-- debugger stops here
...
}
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (!index.isValid())
return;
const MyModel *model = qobject_cast<const MyModel*>(index.model());
...
if(model != 0)
QString first = model->data(index, ItemRoles::First).toString(); // <-- debugger stops here
...
}
To copy to clipboard, switch view to plain text mode
BTW, I don't see a need to get the model, if you need data of the index, you could use
QVariant QModelIndex::data ( int role = Qt::DisplayRole ) const
To copy to clipboard, switch view to plain text mode
Bookmarks