Qt中数据库QSqlQuery该怎么定义啊??急求
这样编译怎么错了呢voidMainWindow::on_pushButton_clicked(){QSqlDatabasedb=QSqlDatabase::addData...
这样编译怎么错了呢
void MainWindow::on_pushButton_clicked()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("sqluser.db");
if(db.open())
{
//QMessageBox::information(this,"warning","YES");
query *obj=new query();
obj->show();
QSqlQuery s;
s.exec("select * from quanbu where zh="+ui->keytxt->text());
}
else
{
QMessageBox::information(this,"warn","NO");
}
} 展开
void MainWindow::on_pushButton_clicked()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("sqluser.db");
if(db.open())
{
//QMessageBox::information(this,"warning","YES");
query *obj=new query();
obj->show();
QSqlQuery s;
s.exec("select * from quanbu where zh="+ui->keytxt->text());
}
else
{
QMessageBox::information(this,"warn","NO");
}
} 展开
展开全部
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("sqluser.db");
db.open();
QString sql("select * from quanbu");
QSqlQueryModel *model = new QSqlQueryModel();
model->setQuery(sql, db);
if (model->lastError().isValid()) {
QDebug() << "Query Error: " << qPrintable(model->lastError().text());
delete model;
model = 0;
} else {
//输出model数据
}
//close database
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询