我想要将日期添加到我的表中,比如说,QTableview.The问题是,如果我将它转换为字符串,我可以添加和检索我想要在模型中存储为data.But的日期。
void MainWindow::setUpTabel()
{
QDateTime myDate;
myDate.setDate(QDate::currentDate());
//myModel
QStandardItemModel model = new QStandardItemModel(this);
QStandardItem *item = new QStandardItem;
item.setData(myDate,Qt::UserRole);
//Myview is also created and set the model to it
m_tableView->setModel(model);
}问题是我不能在我的表中看到日期。
发布于 2014-08-12 16:23:39
正如文档所说,您必须将项目设置到模型中,并指定要设置项目的行和列。
http://qt-project.org/doc/qt-4.8/qstandarditemmodel.html
修改你的代码:
void MainWindow::setUpTabel()
{
int row = 0, column = 0; // here you decide where is the item
QDateTime myDate;
myDate.setDate(QDate::currentDate());
QStandardItemModel model = new QStandardItemModel(this);
QStandardItem *item = new QStandardItem(myDate);
model.setItem(row, column, item);
m_tableView->setModel(model);
}https://stackoverflow.com/questions/21228486
复制相似问题