QT18 how to link QListView with sqlite Database values
来源:互联网 发布:关于编程的电影 编辑:程序博客网 时间:2024/06/06 04:15
1. modify employeeinfo window
2. modify employeeinfo.cpp
#include "employeeinfo.h"#include "ui_employeeinfo.h"#include "login.h"#include <QMessageBox>EmployeeInfo::EmployeeInfo(QWidget *parent) : QDialog(parent), ui(new Ui::EmployeeInfo){ ui->setupUi(this); if(!login::connOpen()) { ui->label_sec_status->setText("Failed to open the database") ; } else { ui->label_sec_status->setText("Connected...") ; }}EmployeeInfo::~EmployeeInfo(){ delete ui;}void EmployeeInfo::on_pushButton_clicked(){ QString eid, name, surname, age; eid = ui->txt_eid->text(); name =ui->txt_name->text(); surname = ui->txt_surname->text(); age = ui->txt_age->text(); if(!login::connOpen()) { qDebug() << "Failed to open the database"; return ; } QSqlQuery qry; QString stmt = "insert into employeeinfo (eid,name,surname,age) values('"+ eid +"','"+ name +"','"+ surname +"','"+ age +"')"; qry.prepare(stmt); if( qry.exec()) { QMessageBox::information(this, tr("Save"), tr("Saved")); login::connClose(); } else { QMessageBox::critical(this, tr("Error"), qry.lastError().text()); }}void EmployeeInfo::on_pushButton_edit_clicked(){ QString eid, name, surname, age; eid = ui->txt_eid->text(); name =ui->txt_name->text(); surname = ui->txt_surname->text(); age = ui->txt_age->text(); if(!login::connOpen()) { qDebug() << "Failed to open the database"; return ; } QSqlQuery qry; QString stmt = "update employeeinfo set eid='"+ eid+"',name='"+ name+ "',surname='"+ surname+"',age='"+ age +"'where eid='" + eid + "'"; qry.prepare(stmt); if( qry.exec()) { QMessageBox::information(this, tr("Edit"), tr("Updated")); login::connClose(); } else { QMessageBox::critical(this, tr("Error"), qry.lastError().text()); }}void EmployeeInfo::on_pushButton_delete_clicked(){ QString eid, name, surname, age; eid = ui->txt_eid->text();// name =ui->txt_name->text();// surname = ui->txt_surname->text();// age = ui->txt_age->text(); if(!login::connOpen()) { qDebug() << "Failed to open the database"; return ; } QSqlQuery qry; QString stmt = "delete from employeeinfo where eid = '"+ eid +"'"; qry.prepare(stmt); if( qry.exec()) { QMessageBox::information(this, tr("Delete"), tr("Deleted")); login::connClose(); } else { QMessageBox::critical(this, tr("Error"), qry.lastError().text()); }}void EmployeeInfo::on_pushButton_load_clicked(){ QSqlQueryModel * modal = new QSqlQueryModel(); login::connOpen(); QSqlQuery* qry = new QSqlQuery(login::mydb); QString stmt; stmt = "select eid, name, surname from employeeinfo"; qry->prepare(stmt); qry->exec(); modal->setQuery(*qry); ui->tableView->setModel(modal); login::connClose(); qDebug() << modal->rowCount();}void EmployeeInfo::on_pushButton_load_list_clicked(){ QSqlQueryModel * modal = new QSqlQueryModel(); login::connOpen(); QSqlQuery* qry = new QSqlQuery(login::mydb); QString stmt; stmt = "select name from employeeinfo"; qry->prepare(stmt); qry->exec(); modal->setQuery(*qry); ui->listView->setModel(modal); login::connClose(); qDebug() << modal->rowCount();}
0 0
- QT18 how to link QListView with sqlite Database values
- QT19 How to link QComboBox with sqlite Database values
- QT14 how to save data in sqlite database with pushbutton
- How to access sqlite database
- This article explains how to use icons with QListView
- How To Auto Complete With Custom Values
- QT22 database values in QLineEdit or textbox if select QListView
- how to use a SQLite database in a standalone program with an HTML interface and VBScript as the programming language
- How to sum values in an array with different hash
- How to replace null values with immediately coming not null values
- How to group Option Button (Form control) with cell link.
- How to seek CEDB Database in wince5 with CEDB_SEEK_VALUEFIRSTEQUAL Parameter?
- How to map asm files with online database files
- How to build database on DB2 with db2 command
- How to display column values in a single cell in Web Intelligence using Oracle database ?
- How to insert double and float values to sqlite?如何向sqlite插入double和float型数据
- Oracle query - how to make count to return values with 0
- SQLite Tutorial 5 : How to Import CSV or Excel file into SQLite database
- android studio 使用技巧
- 设计模式之 抽象工厂模式的扩展(C++实现)
- 转:典型错误:locale.Error:unsupported locale setting
- Qt17 load sqlite table data to qtableview
- 面向对象编程的原则
- QT18 how to link QListView with sqlite Database values
- 为什么Nginx的性能要比Apache高很多?
- 第一章 用神经网络识别手写数字(第一节 感知器)
- Nginx 服务器 select 和epoll的区别
- 项目坑
- 可能你不知道的TClientDataset功能
- QT19 How to link QComboBox with sqlite Database values
- java android中对list的时间进行排序
- 利用 Behavior Driven Development 技术加强软件自动化测试