前言
使用QT5.12.0+VS2017的工具环境进行编译的,所以如果你是使用QtCreator工具的话应该是不能直接编译过去的,这里是需要注意一下的。
整个系统使用的SQLITE数据库进行数据信息的进行保存。因为这个不是商业数据库,所以作为演示的方式的话,使用的小型数据库就可以了,如果是你后期使用超大数据的话,那么可以参考下MYSQL,SqlServer等数据库了。
系统功能包括有,用户登录,学生信息录入,EXECEL表数据导入和导出,学生信息查看等。
一、软件界面




二、登录界面
登录界面跟数据库交互的过程,具体代码如下:
#include "login.h"
#include "ui_login.h"
#define ADMIN_NAME QString("Admin")
#define ADMIN_PWD QString("123456")
Login::Login(QWidget *parent) :
QDialog(parent),
ui(new Ui::Login)
{
ui->setupUi(this);
QString strDatabaseName = QString("%1/%2/%3").arg(QApplication::applicationDirPath()).arg("Database").arg("studentDatabase.db");
QSqlDatabase db;
if (QSqlDatabase::contains(strDatabaseName))
db = QSqlDatabase::database(strDatabaseName);
else
{
db = QSqlDatabase::addDatabase("QSQLITE", strDatabaseName);
db.setDatabaseName(strDatabaseName);
}
query=new QSqlQuery(db);
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
setWindowTitle(tr(u8"用户登录"));
updataData_user();
connect(ui->pushButton_enter,&QPushButton::clicked,this,&Login::clickPushButton_enter);
}
Login::~Login()
{
db.close();
delete ui;
}
void Login::updataData_user()
{
ui->comboBox_username->clear();
//ui->comboBox_username->addItem(ADMIN_NAME);
if(query->exec("select username from user"))
{
while (query->next())
{
QString username = query->value("username").toString();
if(!username.isEmpty())
{
ui->comboBox_username->addItem(username);
}
}
}
}
void Login::clickPushButton_enter()
{
query->clear();
query->exec(QString("select password from user where username = '%1'").arg(ui->comboBox_username->currentText()));
query->next();
if(query->value("password").toString()==ui->lineEdit_password->text()
|| (ui->comboBox_username->currentText() == ADMIN_NAME && ui->lineEdit_password->text() == ADMIN_PWD))
{
MainWindow *mainwindow=new MainWindow(ui->comboBox_username->currentText(),this);
mainwindow->show();
connect(mainwindow,&MainWindow::exitReturnLogin,this,&Login::updataData_user);
hide();
}
else
{
QMessageBox::information(this,u8"提示","用户名或密码错误");
}
}
三、程序下载
代码量还是有点,直接去下载吧
https://download.csdn.net/download/u013083044/86784815

1786

被折叠的 条评论
为什么被折叠?



