使用sqlite作为数据库, 使用下面一的代码, 程序在查询数据库的时候莫名其妙的退出, 试过N次, 皆一样:
1.
QString sql = QString("SELECT amount, rate FROM items WHERE batch=%1")
.arg(ui->batchLineEdit->text().toInt());
QSqlQuery query(sql, DBUtil::getDatabase());
while(query.next()) {
................
}
2.
但是, 如果换成下面这样的, 程序就一直运行正常:
QString sql = QString("SELECT amount, rate FROM items WHERE batch=%1")
.arg(ui->batchLineEdit->text().toInt());
QSqlQuery query(DBUtil::getDatabase());
query.exec(sql);
while(query.next()) {
................
}
原因不名.