【发布时间】:2011-08-04 08:47:34
【问题描述】:
我正在尝试在模型中的TableView 中插入一些数据,但我做错了,因为没有插入数据。不过,该表已更新为列和行。
所以我有一个GraphicsView,我在其中绘制了一些自定义GraphicsItems。每次向场景中添加新项目时,模型都应该更新并向我的TableView 发送信号以将数据也插入其中。
这里我在添加新项目时更新模型:
Clothoid *temp = new Clothoid(); temp->setStartPoint(p1); temp->setEndPoint(p2); clothoids.append(temp); 场景->添加项目(临时); model.setColumnCount(3); model.setRowCount(clothoids.size()); QModelIndex index = model.index(clothoids.size(), 1, QModelIndex()); model.setData(index,clothoids.last()->startCurvature); index = model.index(clothoids.size(), 2, QModelIndex()); model.setData(index,clothoids.last()->endCurvature); index = model.index(clothoids.size(), 3, QModelIndex()); model.setData(index,clothoids.last()->clothoidLength); 发出clothoidAdded(&model);Clothoids 是我的自定义 graphicsItems 的列表:
QList < Clothoid *> 回旋曲线;信号连接到我的主窗口中的插槽:
ui->setupUi(这个); SpinBoxDelegate 委托; ui->clothoidTable->setItemDelegate(&delegate); 连接(ui->graphicsView,SIGNAL(clothoidAdded(QStandardItemModel*)),ui->clothoidTable,SLOT(onClothoidAdded(QStandardItemModel*)));插槽在哪里:
无效 TableViewList::onClothoidAdded(QStandardItemModel *model) { 设置模型(模型); }我做错了什么?
【问题讨论】:
标签: qt4 qtableview qstandarditemmodel