QSqlQueryModel无法从数据库中获取时间

时间:2014-09-24 11:34:38

标签: qt qt5 firebird

我有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);

我的数据库数据:

enter image description here

我的应用显示的内容:

enter image description here

当我运行此代码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 

1 个答案:

答案 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