下载网址:http://www.sqlite.org/download.html
windows 下下载
sqlite-tools-win32-x86-3130000.zip (1.51 MiB) |
A bundle of command-line tools for managing SQLite database files, including the command-line shell program, the sqldiff.exe program, and the sqlite3_analyzer.exe program. (sha1: d74226e1cd38853f792266b221ae70c6c7b26835) |
解压出来
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_Sql = QSqlDatabase::addDatabase("QSQLITE");
m_Sql.setDatabaseName("C:/sqlite/test.db");
if(!m_Sql.open()) {
qFatal("unable to open database");
}
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->tableWidget->setRowCount(0);
QSqlQuery query;
query.exec("SELECT *FROM tablename;");
while (query.next())
{
ui->tableWidget->insertRow(0);
ui->tableWidget->setItem(0, 0, new QTableWidgetItem(query.value(0).toString()));
ui->tableWidget->setItem(0, 1, new QTableWidgetItem(query.value(1).toString()));
}
}
void MainWindow::on_pushButton_2_clicked()
{
QSqlQuery query;
for(int i=0; i<1000000; i++)
{
query.exec("INSERT INTO tablename VALUES(4, 'zhao');");
QApplication::processEvents();
}
}
void MainWindow::on_pushButton_3_clicked()
{
QSqlQuery query;
query.exec("DELETE FROM tablename WHERE id=4;");
}