I have derived from QAbstractItemModel to encode my own tree of data, but the QTreeView is not displaying.
Most of the answers I saw to similar questions were solved because of wrong variable life time, so here is my code for allocation of the model:
ui.tvHierarchy->setModel(
new MetaHierarchyModel(
cutOffExtension(
fileName.toStdString()
)
)
);
On construction the model gets its root node filled with data and later shall load more data as needed (via fetchMore).
I began outputting every function that is called. This is a log of the call sequence:
columnCount( QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return 1
columnCount( QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return 1
columnCount( QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return 1
hasChildren( QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return true
hasChildren( QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return true
canFetchMore( QModelIndex(-1,-1,0x0,QObject(0x0) ) ))
return false
rowCount( QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return 1
index( 0 , 0 , QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return QModelIndex(0,0,0x987aa0,MetaHierarchyModel(0xa16970) )
hasChildren( QModelIndex(0,0,0x987aa0,MetaHierarchyModel(0xa16970) ) )
return true
columnCount( QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return 1
parent( QModelIndex(0,0,0x987aa0,MetaHierarchyModel(0xa16970) ) )
return QModelIndex(-1,-1,0x0,QObject(0x0) )
index( 0 , 0 , QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return QModelIndex(0,0,0x987aa0,MetaHierarchyModel(0xa16970) )
data( QModelIndex(0,0,0x987aa0,MetaHierarchyModel(0xa16970) ) , 13 )
return "Metaparticle 1"
columnCount( QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return 1
parent( QModelIndex(0,0,0x987aa0,MetaHierarchyModel(0xa16970) ) )
return QModelIndex(-1,-1,0x0,QObject(0x0) )
index( 0 , 0 , QModelIndex(-1,-1,0x0,QObject(0x0) ) )
return QModelIndex(0,0,0x987aa0,MetaHierarchyModel(0xa16970) )
data( QModelIndex(0,0,0x987aa0,MetaHierarchyModel(0xa16970) ) , 13 )
return "Metaparticle 1"
Output of roleNames():
QHash((0, "display")(1, "decoration")(2, "edit")(3, "toolTip")(4, "statusTip")(5, "whatsThis"))
The last four lines are then repeated forever (or at least until I loose my patience).
To me it looks like the root data are fetched, but they never get displayed. It is strange, that the last parameter of data - which is int role, has the value 13, which is not defined as any role (still I give back valid strings unconditionally).
Is there anything I missed when implementing this?
datafunction. If you check the docs, you can see that role 13 isQt::SizeHintRole- I'd imagine your view is getting rather confused when that returns a string!QVariant()else. Presumably I had another error back then and now was having this problem all the way. Would you please post it as an answer, so I can mark it correct?