Qt 不显示该表
我有一个基本的组件类。其他的课程都强加给他。我在类followers中实现的所有函数。这些班里有孩子 在我的窗口中,我实现了这个表,在这个表中我必须编写不同类的子类。比如Tsategory的班级,他有孩子。我需要把这些孩子写在桌子上。但是当我在约会的时候,我什么也没表现出来((Qt 不显示该表,qt,qabstractitemmodel,qabstracttablemodel,Qt,Qabstractitemmodel,Qabstracttablemodel,我有一个基本的组件类。其他的课程都强加给他。我在类followers中实现的所有函数。这些班里有孩子 在我的窗口中,我实现了这个表,在这个表中我必须编写不同类的子类。比如Tsategory的班级,他有孩子。我需要把这些孩子写在桌子上。但是当我在约会的时候,我什么也没表现出来(( 您是否检查了mcompositioncomponent是否有子项?@Simon如果我检查了int TableModel::rowCount(const QModelIndex&/*parent*/)const{retur
您是否检查了
mcompositioncomponent
是否有子项?@Simon如果我检查了int TableModel::rowCount(const QModelIndex&/*parent*/)const{return 3;}没有任何更改我询问了包含数据的全局成员mcompositioncomponent
,您检查了吗?
int TableModel::rowCount(const QModelIndex& /*parent*/) const
{
return (int)mCompositeComponent->numChildren();
}
int TableModel::columnCount(const QModelIndex& /*parent*/) const
{
return 3;
}
QVariant TableModel::data(const QModelIndex& index, int role) const
{
int row = index.row();
int col = index.column();
if (role == Qt::DisplayRole)
{
const Component* component = mCompositeComponent->child(row);
if (component != nullptr)
return QString(component->name());
}
return QVariant();
}