【发布时间】:2016-08-17 03:39:04
【问题描述】:
我在Qt Quick 中有一个TreeView 和一个子类QStandardItemModel。 this.appendRow() 在模型的构造函数中工作得很好。
但是,如果我在构造函数之后调用它,例如作为对某个按钮按下的反应,它什么都不做。
(还检查了this->rowCount(),看看它是否可能只是没有显示,但 rowCount 没有增加)。
我正在使用您可以在下面看到的 addRootEntry 函数将QStandardItem 添加到根目录。
void ProjectTreeModel::addRootEntry( const QString& name, const QString& type, const QString& icon)
{
QStandardItem rootEntry = new QStandardItem( name );
rootEntry->setData( icon, ProjectTreeModel_Role_Icon );
rootEntry->setData( type, ProjectTreeModel_Role_Type );
rootEntry->setData( name, ProjectTreeModel_Role_Name );
this->appendRow(rootEntry);
qDebug() << rootEntry; //Is not null
qDebug() << this->rowCount(); //Stays the same
}
【问题讨论】:
标签: c++ qt user-interface qt5