我有QSqlQueryModel的问题,它工作正常,直到我想从数据库获取时间。使用Firebird 2.5数据库。
matchModel = new QSqlQueryModel(this);
matchModel->setQuery("Select * from mecz");
ui->matchTableView->setModel(matchModel);
ui->matchTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
ui->matchTableView->horizontalHeader()->setStretchLastSection(true);
我的数据库数据:
我的应用显示的内容:
当我运行此代码qDebug() << matchModel->index(0,4).data().toTime().toString();
时,我得到空值(""
)。
修改
我找到了一个临时解决方案。将查询更改为:
Select id, druzyna_gospodarz, druzyna_gosc, data_meczu, EXTRACT(HOUR from CAST(godzina_meczu as TIMESTAMP)) || ':' || IIF(CHAR_LENGTH(EXTRACT(MINUTE from CAST(godzina_meczu as TIMESTAMP)))>1,EXTRACT(MINUTE from CAST(godzina_meczu as TIMESTAMP)),'0' || EXTRACT(MINUTE from CAST(godzina_meczu as TIMESTAMP))) from mecz
答案 0 :(得分:0)
临时解决方案。只需将查询更改为:
Select id, druzyna_gospodarz, druzyna_gosc, data_meczu, EXTRACT(HOUR from CAST(godzina_meczu as TIMESTAMP)) || ':' || IIF(CHAR_LENGTH(EXTRACT(MINUTE from CAST(godzina_meczu as TIMESTAMP)))>1,EXTRACT(MINUTE from CAST(godzina_meczu as TIMESTAMP)),'0' || EXTRACT(MINUTE from CAST(godzina_meczu as TIMESTAMP))) from mecz