mainwindow.cpp
view plaincopy to clipboardprint?
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->queryButton,SIGNAL(clicked()),this,SLOT(queryDatabaseSlot()));
}
MainWindow::~MainWindow()
{
delete ui;
}
#include
void MainWindow::queryDatabaseSlot()
{
//#include
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
//db.setHostName("bigblue");
db.setDatabaseName("student.db");
//db.setUserName("acarlson");
// db.setPassword("1uTbSbAs");
bool ok = db.open();
if(ok)
{
QSqlQuery query(db);
query.exec("select *from information");
//store the data in buffer
while (query.next())
{
QString id = query.value(0).toString();
QString name= query.value(1).toString();
QString address=query.value(2).toString();
QString nickName=query.value(3).toString();
qDebug() << id << name< db.close();
}
}
else
{
QMessageBox::information(this,"Error Message",db.lastError().text());
}
}
阅读(1083) | 评论(0) | 转发(0) |