首页
资源库
留言板
站点统计
Search
1
[Java] @Data 注解 代码变得简洁
205 阅读
2
[Vue] Vue 使用ElementUI组件
162 阅读
3
[Java] 安装JDK8
131 阅读
4
[Java] 发送消息
122 阅读
5
[C语言] 游戏贪吃蛇
108 阅读
Tools
编程
C/C++
Java
mySQL
python
PHP
Vue
嵌入式系统编程
HTML
数据结构
TypeScript
登录
Search
标签搜索
Java
SpringBoot
数据结构
C/C++
mysql
Vue
tools
redis
游戏
TomCat
linux
arm
嵌入式系统
Mqtt
PHP
maven
图床
github
IDEA
jar
星如雨
累计撰写
48
篇文章
累计收到
2
条评论
首页
栏目
Tools
编程
C/C++
Java
mySQL
python
PHP
Vue
嵌入式系统编程
HTML
数据结构
TypeScript
页面
资源库
留言板
站点统计
搜索到
2
篇与
的结果
2022-06-15
[QT] QT SQLite 实现增删改查
1.在工程文件下使用sql(*.pro 输入QT+=sql)2.初始化页面设计3. 写代码3.1 连接数据库的头文件书写#ifndef CONNECTION_H #define CONNECTION_H #include <QSqlDatabase> #include <QMessageBox> #include <QSqlQuery> static bool CreateConnectDatabase(){ QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("test.db"); if( !db.open() ) { QMessageBox box; box.setText("open database fail"); return false; } QSqlQuery query; query.exec("create table SQLite(id integer primary key, name varchar(20) )"); return true; } #endif3.2 主函数调用#include <QtGui/QApplication> #include "mainwindow.h" #include "connection.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); if(! CreateConnectDatabase() ){ return false; } MainWindow w; w.show(); return a.exec(); }3.3 窗口头文件定义槽函数private slots: void on_lineEdit_1_textChanged(QString value); void on_lineEdit_2_textChanged(QString value); void on_Button_1_clicked(); void on_Button_2_clicked(); void on_Button_3_clicked(); void on_Button_4_clicked(); void on_Button_5_clicked();3.4 实现槽函数void MainWindow::on_lineEdit_1_textChanged(QString value){ idValue = value; } void MainWindow::on_lineEdit_2_textChanged(QString value){ nameValue = value; } // show void MainWindow::on_Button_1_clicked(){ QSqlQuery query; query.exec("select id,name from SQLite"); QStandardItemModel *model = new QStandardItemModel; this->ui->tableView->setModel(model); model->setHorizontalHeaderItem(0, new QStandardItem("id")); model->setHorizontalHeaderItem(1, new QStandardItem("name")); int i = 0; while( query.next() ){ ui->label->setText("select ok"); model->setItem(i, 0, new QStandardItem( query.value(0).toString() ) ); model->setItem(i, 1, new QStandardItem( query.value(1).toString() ) ); i += 1; } } void MainWindow::on_Button_2_clicked(){ if(idValue == "" || nameValue == ""){ ui->label->setText("id or name is none"); }else{ QSqlQuery query; query.exec("select id from SQLite where id='" + idValue + "'"); if(! query.next()){ query.exec("insert into SQLite(id, name) values( " + idValue + ",'" + nameValue + "')"); ui->label->setText("insert id=" + QString(idValue) +" success"); ui->lineEdit_1->setText(""); ui->lineEdit_2->setText(""); }else{ ui->label->setText("insert existed"); } } } void MainWindow::on_Button_3_clicked(){ if(idValue == "" || nameValue == ""){ ui->label->setText("id or name is none"); }else{ QSqlQuery query; query.exec("select id from SQLite where id='" + idValue + "'"); if( query.next()){ query.exec("update SQLite set name = '" + nameValue + "' where id=" + idValue ); ui->label->setText("update id=" + QString(idValue) +" success"); ui->lineEdit_1->setText(""); ui->lineEdit_2->setText(""); }else{ ui->label->setText("update not existed"); } } } void MainWindow::on_Button_4_clicked(){ QSqlQuery query; query.exec("delete from SQLite"); ui->label->setText("delete ok"); } void MainWindow::on_Button_5_clicked(){ qApp->quit(); }4 运行此时没有任何数据插入数据 1 123查询数据更新数据 1 456删除数据(删除所有数据)
2022年06月15日
100 阅读
0 评论
0 点赞
2022-04-28
[arm] 嵌入式系统找不到 gcc
问题在使用 arm-cortex_a8-linux-gnueabi-gcc 时,发现提示找不到gcc 文件(已经存在并且配置过环境变量)file ~/嵌入式系统编程/toolchain/arm-cortex_a8/bin/arm-cortex_a8-linux-gnueabi-gccLinux 是 64位,但gcc 是 32 位获取 32位库sudo apt install lib32z1{message type="success" content="完成"/}
2022年04月28日
35 阅读
0 评论
0 点赞