QT14 how to save data in sqlite database with pushbutton
发布时间:2020-12-12 19:32:24 所属栏目:百科 来源:网络整理
导读:1. reedit the employinfo window like 2.reedit the employinfo.cpp as #include "employeeinfo.h"#include "ui_employeeinfo.h"#include "login.h"#include QMessageBoxEmployeeInfo::EmployeeInfo(QWidget *parent) : QDialog(parent),ui(new Ui::Employe
1. reedit the employinfo window like
2.reedit the employinfo.cpp as
#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,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()); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |