C++实现图书管理系统(Qt C++ GUI界面版)

前瞻
本项目基于【C++】图书管理系统(完整版)

图书管理系统功能概览:

  1. 登录,注册
  2. 学生,老师借书,查看自己当前借书情况,还书。
  3. 管理员增加书,查看当前借阅情况,查看当前所有借阅人,图书信息。

效果概览:
登录:输入用户名和密码,选择对应角色(管理员、学生、老师),点击登录,对应信息存储在txt文件中,程序会自动校验是否输入的用户名和密码存在并对应
在这里插入图片描述
在这里插入图片描述

注册:当用户点击注册时,将跳转到注册页面,程序会将用户信息存入txt文件中,注册成功后,会自动跳转到登录界面,用户也可以通过点击登录按钮跳转回登录界面
在这里插入图片描述
用户界面(学生或老师):当用户登录成功后,进入操作界面,包括功能如下:
借书:
在这里插入图片描述
查看自己借阅情况
在这里插入图片描述
还书:
在这里插入图片描述
管理员界面: 包括功能如下:
增加书:
在这里插入图片描述
查看当前借阅情况:
在这里插入图片描述
查看所有图书:
在这里插入图片描述
查看借阅人详细信息:
在这里插入图片描述
目前该系统大致功能如上。

代码概览:

各个模块主要负责功能
主要用于数据处理、存储部分,类似后端CBook.h  用于对书抽象,并实现了>>的重载,便于文件读入,读出CUser.h  工具人,作为老师,学生的父类CStudent.h  对学生进行的抽象CTeacher.h 对老师进行的抽象CAdministrator.h 对管理的抽象CManagementBooks.h  用户所有的相关操作的中间执行者,有设计模式中代理的思想QtLibrarySystem.cpp  界面的的实现与系统入口主要用于数据暂时,处理用户输入,类似前端RegistrationPage.h 注册界面实现类UserPage.h用户界面实现类LoginPage.h登录界面实现类AdminPage.h管理员界面实现类

说明:获取方式见文章最后,点击查看,还有就是文件读入建议大家都直接放在相应项目里面,不然就写绝对路径。有问题欢迎大家在评论区提问,喜欢就点个赞咯!


全部代码与讲解:

CUser.cpp

#include "CUser.h"
#include<iostream>
#include<fstream>
using namespace std;CUser::CUser()
{m_name = "陈1";
}void CUser::setId(string id)
{m_id = id;
}void CUser::setName(string name)
{m_name = name;
}void CUser::setGender(string gender)
{m_gender = gender;
}void CUser::setDepartment(string department)
{m_department = department;
}void CUser::setPhone(string phone)
{m_phone = phone;
}CUser::~CUser()
{
}string CUser::returnBook(CManagementBooks& mb,string bookName)
{int all = mb.checkBorrowedBook(m_id);if (all == 0){return  "您暂未借书,无需归还";}else{if (mb.checkTrueBorrow(m_id, bookName)){mb.Return(m_id, bookName);return "";}else{return "您并未借阅此书";}}return "";
}string CUser::getId()
{return m_id;
}string CUser::getName()
{return m_name;
}string CUser::getGender()
{return m_gender;
}string CUser::getDepartment()
{return m_department;
}string CUser::getPhone()
{return m_phone;
}std::ostream& operator<<(std::ostream& os, const CUser* user)
{os << endl << user->m_id << " " << user->m_name << " " << user->m_gender << " " << user->m_department << " " << user->m_phone;return os;
}std::istream& operator>>(std::istream& is, CUser* user)
{is >> user->m_id >> user->m_name >> user->m_gender >> user->m_department >> user->m_phone;return is;
}

CTeacher.cpp

#include "CTeacher.h"
#include<fstream>CTeacher::CTeacher()
{m_name = "刘一";
}string CTeacher::borrowBookFromLibrary(CManagementBooks& mb, string name)
{int all = mb.checkBorrowedBook(m_id);if (all < 5){if (mb.borrow(name)){ofstream writeFile("borrowedBook.txt", ios::app);mb.setMapValue(m_id, name);writeFile << endl << m_id << " " << name;writeFile.close();}}else{return "您已经超过了最大可借阅数";}return "";
}
void CTeacher::showInfo()
{cout << "姓名:" << m_name << " " << "学号:" << m_id << " " << "性别:" << m_gender << " " << "院系:" << m_department << " " << "联系方式:" << m_phone << endl;
}

CStudent.cpp

#include "CStudent.h"
#include<fstream>
using  namespace std;CStudent::CStudent()
{m_class = "软件";
}void CStudent::showInfo()
{cout << "姓名:" << m_name << " " << "学号:" << m_id << " " << "性别:" << m_gender << " " << "院系:" << m_department << " " << "班级:" << m_class << " " << "联系方式:" << m_phone << endl;
}string CStudent::borrowBookFromLibrary(CManagementBooks& mb, string name)
{int all = mb.checkBorrowedBook(m_id);if (all < 3){if (mb.borrow(name)){ofstream writeFile("borrowedBook.txt", ios::app);mb.setMapValue(m_id, name);writeFile << endl << m_id << " " << name;writeFile.close();}else{return "此书数量不足或暂无此书";}}else{return "您已经超过了最大可借阅数";}return "";}void CStudent::setClass(string Class)
{m_class = Class;
}string CStudent::getClass()
{return m_class;
}

CManagementBooks.cpp

#include "CManagementBooks.h"
#include<algorithm>
using namespace std;
static bool cmp(CBook book1, CBook book2)
{return book1.getNum() > book2.getNum();
}
void CManagementBooks::showCurrentAllBook()
{sort(m_books.begin(), m_books.end(), cmp);for (int i = 0; i < m_allBookNum; i++){cout << "书名:" << m_books[i].getName() << " " << "剩余数量" << m_books[i].getNum() << endl;}
}CManagementBooks::CManagementBooks()
{m_allBookNum = 0;
}void CManagementBooks::addBook(CBook book)
{int flag = 0;for (int i = 0; i < m_allBookNum; i++){if (m_books[i].getName() == book.getName()){flag = 1;m_books[i].setNum(m_books[i].getNum() + book.getNum());ofstream writeFile("library.txt", ios::out);for (int i = 0; i < m_allBookNum; i++){writeFile << m_books[i];}writeFile.close();break;}}if (!flag){ofstream writeFile("library.txt", ios::app);m_books.push_back(book);m_allBookNum++;writeFile << book;writeFile.close();}
}int CManagementBooks::getAllBookNum()
{return m_allBookNum;
}void CManagementBooks::showAllBooksInfo()
{sort(m_books.begin(), m_books.end(), cmp);for (int i = 0; i < m_allBookNum; i++){m_books[i].showInfo();}
}bool CManagementBooks::borrow(string name)
{for (int i = 0; i < m_allBookNum; i++){if (m_books[i].getName() == name){if (m_books[i].getNum() >= 1){m_books[i].setNum(m_books[i].getNum() - 1);ofstream writeFile("library.txt");for (int i = 0; i < m_allBookNum; i++){writeFile << m_books[i];}writeFile.close();return true;}else{return false;}}}return false;
}void CManagementBooks::Return(string id, string bookName)
{CBook book;book.setName(bookName);addBook(book);ofstream writeFile("borrowedBook.txt", ios::out);for (auto iter = m_outBookMap.begin(); iter != m_outBookMap.end(); ++iter){if (iter->first == id && iter->second == bookName){m_outBookMap.erase(iter);break;}}for (auto map : m_outBookMap){writeFile << endl << map.first << " " << map.second;}writeFile.close();
}void CManagementBooks::initOutBook()
{ifstream readFile("borrowedBook.txt");if (!readFile.is_open()){cout << "查看全体借书情况数据读取出错" << endl;}else{while (!readFile.eof()){string studentId, bookName;readFile >> studentId >> bookName;m_outBookMap.insert(pair<string, string>(studentId, bookName));}}readFile.close();}void CManagementBooks::checekOutBook()
{for (auto map : m_outBookMap){cout << "借阅人学工号:" << map.first << " " << "借阅书名:" << map.second << endl;}
}void CManagementBooks::initBooks()
{ifstream readFile;readFile.open("library.txt");if (!readFile.is_open()){cout << "图书数据读取错误" << endl;readFile.close();return;}while (!readFile.eof()){CBook book;readFile >> book;m_allBookNum++;m_books.push_back(book);}readFile.close();
}int CManagementBooks::checkBorrowedBook(string userId)
{int flag = 0;for (auto map : m_outBookMap){if (userId == map.first){if (!flag){cout << "您已经借的全部图书如下:" << endl;flag++;}else{flag++;}cout << map.second << " ";}}if (!flag){cout << "您目前没有借书" << endl;}cout << "共:" << flag << "本";cout << endl;return flag;
}vector<userInfo> CManagementBooks::viewBorrowerDetails()
{ifstream readFile("teacher.txt");ifstream readFile1("student.txt");vector<userInfo>users;if (!readFile1.is_open() || !readFile.is_open()){cout << "用户数据读取错误" << endl;}while (!readFile1.eof()){string act1, name, department, gender,phone;readFile1 >> act1 >> name >> gender >> department>> phone;if(act1!="" && name != "")users.push_back({ act1,name ,gender ,department,"学生",phone});}while (!readFile.eof()){string act1, name, department, gender, phone;readFile >> act1 >> name >> gender >> department;if (act1 != "" && name != "")users.push_back({ act1,name ,gender ,department,"老师",phone });}readFile.close();readFile1.close();return users;
}bool CManagementBooks::checkTrueBorrow(string id, string bookName)
{for (auto map : m_outBookMap){if (map.first == id && map.second == bookName){return true;}}return false;
}void CManagementBooks::setMapValue(string userId, string bookName)
{m_outBookMap.insert(pair<string, string>(userId, bookName));
}vector<CBook> CManagementBooks::getAllBook()
{return m_books;
}unordered_multimap<string, string> CManagementBooks::getOutBookMap()
{return m_outBookMap;
}

CBook.cpp

#include "CBook.h"
#include <iostream>
#include<fstream>
using namespace std;CBook::CBook()
{string b = "";string randStr = "0123456789X";for (int i = 0; i <= 12; i++){if (i == 1 || i == 5 || i == 11){b += '-';}else{if (i == 12){b += randStr[rand() % 11];}else{b += randStr[rand() % 10];}}}m_num = 1;m_name = "等待戈多";m_author = "xx元";m_isbn = b;m_page = rand();m_pressInfo = "xx出版社";m_price = rand();
}void CBook::setNum(int num)
{m_num = num;
}int CBook::getNum()
{return m_num;
}void CBook::setName(string name)
{m_name = name;
}string CBook::getName()
{return m_name;
}void CBook::setIsbn(string isbn)
{m_isbn = isbn;
}string CBook::getIsbn()
{return m_isbn;
}void CBook::setPressInfo(string perssInfo)
{m_pressInfo = perssInfo;
}string CBook::getPressInfo()
{return m_pressInfo;
}void CBook::setPrice(double price)
{m_price = price;
}double CBook::getPrice()
{return m_price;
}void CBook::setPage(int page)
{m_page = page;}int CBook::getPage()
{return m_page;
}void CBook::setAuthor(string author)
{m_author = author;
}string CBook::getAuthor()
{return m_author;
}void CBook::checkIsnb()
{int sum = 0;for (int i = 0, j = 1; i < m_isbn.size(); i++) {if (m_isbn[i] != '-' && i != 12) {sum += (m_isbn[i] - '0') * j;j++;}}sum %= 11;char c = 'X';if (sum < 10) c = sum + '0';if (m_isbn[12] == c) puts("This book isbn are Right!");else puts("This book isbn are wrong!");
}bool CBook::isBorrowed()
{if (m_num >= 1){m_num--;return true;}return false;
}void CBook::showInfo()
{cout << "作者:" << m_author << " " << "isbn号码:" << m_isbn << " " << "书本名称:" << m_name << " "<< "总页数:" << m_page << " " << "出版社:" << m_pressInfo << " " << "价格:" << m_price<< " " << "剩余本数:" << m_num << endl;
}std::ostream& operator <<(std::ostream& os, const CBook& book)
{os << endl << book.m_name << " " << book.m_isbn << " " << book.m_pressInfo << " " << book.m_price << " " << book.m_page << " " << book.m_author << " " << book.m_num;return os;
}std::istream& operator>>(std::istream& is, CBook& book)
{is >> book.m_name >> book.m_isbn >> book.m_pressInfo >> book.m_price >> book.m_page >> book.m_author >> book.m_num;return is;
}}

userPage.cpp

#include "UserPage.h"
#include <QMessageBox>
#include <QFont>UserPage::UserPage(QWidget* parent) : QWidget(parent)
{// 创建主布局QVBoxLayout* mainLayout = new QVBoxLayout(this);setWidgetFont(this);// 创建选项卡部件tabWidget = new QTabWidget(this);// 借书选项卡// 创建显示当前图书列表的QTableWidgetQTableWidget* currentBooksList = new QTableWidget(borrowTab);currentBooksList->setObjectName("currentBooksList");setWidgetFont(currentBooksList);// 创建标签用于说明图书列表QLabel* currentBooksLabel = createStyledLabel("当前图书列表:");borrowLayout->addWidget(currentBooksLabel);borrowLayout->addWidget(currentBooksList);// 添加书名输入标签和输入框QLabel* bookNameLabel = createStyledLabel("输入要借的书名:");borrowLayout->addWidget(bookNameLabel);borrowLayout->addWidget(bookNameEdit);borrowLayout->addWidget(borrowButton);tabWidget->addTab(borrowTab, "借书");// 查看借书情况选项卡// 还书选项卡mainLayout->addWidget(tabWidget);// 设置编码codec = QTextCodec::codecForName("GBK");// 连接借书按钮点击事件connect(borrowButton, &QPushButton::clicked, this, &UserPage::onBorrowButtonClicked);// 连接还书按钮点击事件connect(returnButton, &QPushButton::clicked, this, &UserPage::onReturnButtonClicked);connect(tabWidget, &QTabWidget::currentChanged, [this](int index) {if (index == tabWidget->indexOf(borrowedBooksTab)) {onViewBorrowedBooksClicked();}else if (index == tabWidget->indexOf(returnTab)) {onShowBorrowedBooksForReturnClicked();}else if (index == tabWidget->indexOf(borrowTab)) {onBorrowTabClicked();}});mb.initBooks();mb.initOutBook();initCurrentBookList();
}void UserPage::onBorrowButtonClicked()
{QString bookName = bookNameEdit->text();if (bookName.isEmpty()){QMessageBox::warning(this,"借书提示","请输入要借的书名");return;}std::string allow = user->borrowBookFromLibrary(mb, codec->fromUnicode(bookName).toStdString());if (allow != ""){QMessageBox::critical(this, "借书失败", codec->toUnicode(allow.c_str()));return;}// 尝试获取当前图书列表部件QTableWidget* currentBooksList = this->findChild<QTableWidget*>("currentBooksList");if (currentBooksList){QList<QTableWidgetItem*> foundItems = currentBooksList->findItems(bookName, Qt::MatchExactly);if (!foundItems.isEmpty()){QTableWidgetItem* itemToModify = foundItems.first();int row = currentBooksList->row(itemToModify);// 获取当前可借数量并减1QTableWidgetItem* numItem = currentBooksList->item(row, 6);int currentNum = numItem->text().toInt();if (currentNum > 0){currentNum--;numItem->text() = QString::number(currentNum);QMessageBox::information(this, "借书成功", "已成功借阅 " + bookName);// 重新加载图书数据onBorrowTabClicked();}}}
}void UserPage::onReturnButtonClicked()
{QList<QTableWidgetItem*> selectedItems = returnableBooksList->selectedItems();if (selectedItems.isEmpty()){QMessageBox::warning(this, "还书提示", "请选择要归还的书籍");return;}// 使用QSet来避免重复添加书籍IDQSet<QString> addedBookIds;QList<QString> bookIds;for (QTableWidgetItem* item : selectedItems){// 获取该项所在行的索引int row = returnableBooksList->row(item);// 获取该行第二列的表格项(索引为1)QTableWidgetItem* secondColumnItem = returnableBooksList->item(row, 1);if (secondColumnItem){QString bookId = secondColumnItem->text();if (!addedBookIds.contains(bookId)){bookIds.append(bookId);addedBookIds.insert(bookId);}}}// 执行还书操作,假设user有还书相关函数,mb是管理书籍相关数据的对象std::string result;for (const QString& bookId : bookIds){// 这里调用还书函数,根据实际情况可能需要调整参数传递方式result = user->returnBook(mb, codec->fromUnicode(bookId).toStdString());if (result != ""){break;}}if (result == ""){// 还书成功,更新界面显示QMessageBox::information(this, "还书成功", "已成功归还所选书籍");// 重新加载当前用户借阅的书籍列表,以更新界面显示onShowBorrowedBooksForReturnClicked();}else{QMessageBox::warning(this, "还书失败", codec->toUnicode(result.c_str()));}
}QLabel* UserPage::createStyledLabel(const QString& text)
{QLabel* label = new QLabel(text);setWidgetFont(label);return label;
}void UserPage::setWidgetFont(QWidget* widget)
{QFont font;font.setFamily("宋体");font.setPointSize(16);widget->setFont(font);
}void UserPage::initCurrentBookList()
{// 清空之前的显示内容QTableWidget* currentBooksList = this->findChild<QTableWidget*>("currentBooksList");currentBooksList->setEditTriggers(QAbstractItemView::NoEditTriggers);if (currentBooksList){// 设置表格列数和表头currentBooksList->setColumnCount(7);QStringList headers;headers << "作者" << "isbn号码" << "书本名称" << "总页数" << "出版社" << "价格" << "剩余本数";currentBooksList->setHorizontalHeaderLabels(headers);// 设置表格字体大小QFont tableFont;tableFont.setPointSize(10); // 设置字体大小为12,你可以根据需要调整这个值currentBooksList->setFont(tableFont);// 设置表头字体大小QHeaderView* headerView = currentBooksList->horizontalHeader();QFont headerFont;headerFont.setPointSize(10); // 设置字体大小为12,你可以根据需要调整这个值headerView->setFont(headerFont);// 添加书籍信息for (auto& book : mb.getAllBook()){int row = currentBooksList->rowCount();currentBooksList->insertRow(row);QTableWidgetItem* authorItem = new QTableWidgetItem(codec->toUnicode(book.getAuthor().c_str()));QTableWidgetItem* isbnItem = new QTableWidgetItem(codec->toUnicode(book.getIsbn().c_str()));QTableWidgetItem* nameItem = new QTableWidgetItem(codec->toUnicode(book.getName().c_str()));QTableWidgetItem* pressInfoItem = new QTableWidgetItem(codec->toUnicode(book.getPressInfo().c_str()));QTableWidgetItem* pagesItem = new QTableWidgetItem((QString::number(book.getPage())));QTableWidgetItem* priceItem = new QTableWidgetItem((QString::number(book.getPrice())));QTableWidgetItem* numItem = new QTableWidgetItem(QString::number(book.getNum()));currentBooksList->setItem(row, 0, authorItem);currentBooksList->setItem(row, 1, isbnItem);currentBooksList->setItem(row, 2, nameItem);currentBooksList->setItem(row, 3, pagesItem);currentBooksList->setItem(row, 4, pressInfoItem);currentBooksList->setItem(row, 5, priceItem);currentBooksList->setItem(row, 6, numItem);}}// 设置列宽,这里的宽度值可以根据实际情况调整currentBooksList->setColumnWidth(0, 150);currentBooksList->setColumnWidth(1, 150);currentBooksList->setColumnWidth(2, 200);currentBooksList->setColumnWidth(3, 100);currentBooksList->setColumnWidth(4, 200);currentBooksList->setColumnWidth(5, 100);currentBooksList->setColumnWidth(6, 100);
}void UserPage::onUserUpdated(CUser* user)
{this->user = user;
}void UserPage::onViewBorrowedBooksClicked()
{// 清空之前的显示内容borrowedBooksList->clearContents();borrowedBooksList->setRowCount(0);// 设置表格列数和表头borrowedBooksList->setColumnCount(2);borrowedBooksList->setEditTriggers(QAbstractItemView::NoEditTriggers);QStringList headers;headers << "借阅者账号" << "借阅图书";borrowedBooksList->setHorizontalHeaderLabels(headers);// 获取当前用户的借书信息列表std::unordered_multimap<string, string> borrowedBooks = mb.getOutBookMap();// 添加借书信息到表格中for (const auto& book : borrowedBooks) {if (book.first != user->getId()) continue;int row = borrowedBooksList->rowCount();borrowedBooksList->insertRow(row);QTableWidgetItem* bookNameItem = new QTableWidgetItem(codec->toUnicode(book.first.c_str()));QTableWidgetItem* authorItem = new QTableWidgetItem(codec->toUnicode(book.second.c_str()));borrowedBooksList->setItem(row, 0, bookNameItem);borrowedBooksList->setItem(row, 1, authorItem);}borrowedBooksList->setColumnWidth(0, 500);borrowedBooksList->setColumnWidth(1, 500);
}void UserPage::onShowBorrowedBooksForReturnClicked()
{// 设置选择模式为单选整行returnableBooksList->setSelectionBehavior(QAbstractItemView::SelectRows);returnableBooksList->setSelectionMode(QAbstractItemView::SingleSelection);
}
void UserPage::onBorrowTabClicked()
{// 清空之前的显示内容}

loginPage.cpp

#include "LoginPage.h"LoginPage::LoginPage(QWidget* parent) : QWidget(parent)
{// 创建用户名输入框usernameEdit = new QLineEdit(this);// 创建密码输入框,并设置为密码模式passwordEdit = new QLineEdit(this);setWidgetFontAndSize(passwordEdit);setInputBoxHeight(passwordEdit, 35); // 设置用户名输入框高度// 创建角色选择下拉框roleLoginComboBox = new QComboBox(this);roleLoginComboBox->addItems({ "学生", "老师", "管理员" });setWidgetFont(roleLoginComboBox);// 创建登录按钮loginButton = new QPushButton("登录", this);setWidgetFont(loginButton);// 创建注册按钮registerButton = new QPushButton("注册", this);setWidgetFont(registerButton);// 设置布局QVBoxLayout* mainLayout = new QVBoxLayout(this);QHBoxLayout* usernameLayout = new QHBoxLayout();usernameLayout->addWidget(createStyledLabel("用户名:"));usernameLayout->addWidget(usernameEdit);mainLayout->addLayout(usernameLayout);QHBoxLayout* passwordLayout = new QHBoxLayout();passwordLayout->addWidget(createStyledLabel("密码:"));passwordLayout->addWidget(passwordEdit);mainLayout->addLayout(passwordLayout);QHBoxLayout* roleLoginLayout = new QHBoxLayout();roleLoginLayout->addWidget(createStyledLabel("角色:"));roleLoginLayout->addWidget(roleLoginComboBox);mainLayout->addLayout(roleLoginLayout);QHBoxLayout* buttonLayout = new QHBoxLayout();buttonLayout->addWidget(loginButton);buttonLayout->addWidget(registerButton);mainLayout->addLayout(buttonLayout);// 连接按钮点击事件到相应的槽函数connect(loginButton, &QPushButton::clicked, this, &LoginPage::onLoginButtonClicked);connect(registerButton, &QPushButton::clicked, this, &LoginPage::onRegisterButtonClicked);
}void LoginPage::onLoginButtonClicked()
{QString account = usernameEdit->text();QString password = passwordEdit->text();QString role = roleLoginComboBox->currentText();CUser* user = nullptr;CAdministrator admin;if (account.isEmpty() || password.isEmpty()){QMessageBox::critical(this, "错误", "用户名或密码不能为空!");return;}std::ifstream readFile;std::ifstream readFile1;if (role == "老师"){readFile.open("teacherLogin.txt");readFile1.open("teacher.txt");user = new CTeacher();}else if(role == "学生"){readFile1.open("student.txt");readFile.open("studentLogin.txt");user = new CStudent();}else{readFile1.open("admin.txt");readFile.open("adminLogin.txt");int flag = 0;while (!readFile.eof()){std::string act;readFile >> act;if (act == account.toStdString()){std::string pwd;readFile >> pwd;if (pwd == password.toStdString()){QMessageBox::about(this, "登录成功", "登录成功!");flag = 1;while (!readFile1.eof()){readFile1 >> admin;if (admin.getId() == act){emit adminUpdated(admin);break;}}break;}}}if (!flag){QMessageBox::critical(this, "错误", "用户名或密码错误!");return;}emit adminLoginSuccess();readFile.close();readFile1.close();return;}int flag = 0;while (!readFile.eof()){std::string act;readFile >> act;if (act == account.toStdString()){std::string pwd;readFile >> pwd;if (pwd == password.toStdString()){QMessageBox::about(this, "登录成功", "登录成功!");flag = 1;while (!readFile1.eof()){readFile1 >> user;if (user != nullptr && user->getId() == act){emit userUpdated(user);break;}}break;}}}if (!flag){QMessageBox::critical(this, "错误", "用户名或密码错误!");return;}emit loginSuccess();readFile.close();readFile1.close();
}void LoginPage::onRegisterButtonClicked()
{emit registerButtonClicked();
}// 设置输入框宽度的函数
void LoginPage::setInputBoxWidth(QWidget* widget, int width)
{widget->setFixedWidth(width);
}// 创建带有指定样式的标签函数
QLabel* LoginPage::createStyledLabel(const QString& text)
{QLabel* label = new QLabel(text);setWidgetFont(label);return label;
}// 设置输入框字体和大小的函数
void LoginPage::setWidgetFontAndSize(QWidget* widget)
{QFont font;font.setFamily("宋体");font.setPointSize(16);widget->setFont(font);
}
void LoginPage::setInputBoxHeight(QWidget* widget, int height)
{widget->setFixedHeight(height);
}// 设置按钮字体的函数
void LoginPage::setWidgetFont(QWidget* widget)
{QFont font;font.setFamily("宋体");font.setPointSize(16);widget->setFont(font);
}

register.cpp

#include "RegistrationPage.h"
#include <QFont>RegistrationPage::RegistrationPage(QWidget* parent) : QWidget(parent)
{// 创建用户名输入框usernameEdit = new QTextEdit(this);setWidgetFontAndSize(usernameEdit);setInputBoxHeight(usernameEdit, 35); // 设置用户名输入框高度// 创建姓名输入框nameEdit = new QTextEdit(this);setWidgetFontAndSize(nameEdit);setInputBoxHeight(nameEdit, 35); // 设置姓名输入框高度// 创建部门输入框departmentEdit = new QTextEdit(this);setWidgetFontAndSize(departmentEdit);setInputBoxHeight(departmentEdit, 35); // 设置部门输入框高度// 创建电话输入框phoneEdit = new QTextEdit(this);setWidgetFontAndSize(phoneEdit);setInputBoxHeight(phoneEdit, 35); // 设置电话输入框高度// 创建密码输入框,并设置为密码模式passwordEdit = new QTextEdit(this);setWidgetFontAndSize(passwordEdit);setInputBoxHeight(passwordEdit, 35); // 设置密码输入框高度// 创建性别选择下拉框genderComboBox = new QComboBox(this);genderComboBox->addItems({ "男", "女" });setWidgetFont(genderComboBox);// 创建角色选择下拉框roleLoginComboBox = new QComboBox(this);roleLoginComboBox->addItems({ "学生", "老师", "管理员" });setWidgetFont(roleLoginComboBox);// 创建注册按钮registerButton = new QPushButton("注册", this);setWidgetFont(registerButton);// 创建登录按钮loginButton = new QPushButton("登录", this);setWidgetFont(loginButton);// 连接注册按钮的点击事件到槽函数connect(registerButton, &QPushButton::clicked, this, &RegistrationPage::onRegisterButtonClicked);connect(loginButton, &QPushButton::clicked, this, &RegistrationPage::onLoginButtonClicked); // 连接登录按钮点击事件
}void RegistrationPage::onRegisterButtonClicked()
{QString act = usernameEdit->toPlainText();QString name = nameEdit->toPlainText();QString department = departmentEdit->toPlainText();QString phone = phoneEdit->toPlainText();QString pwd = passwordEdit->toPlainText();QString gender = genderComboBox->currentText();QString role = roleLoginComboBox->currentText();if (act == "" || name == "" || department == "" || phone == ""){QMessageBox::critical(this, "错误", "请将信息补充完整!");return;}if (role == "管理员"){QMessageBox::critical(this, "错误", "管理员无法注册!");return;}std::ofstream writeFile;std::ofstream writeFile1;if (role == "老师"){writeFile1.open("teacher.txt", std::ios::app);writeFile.open("teacherLogin.txt", std::ios::app);}else{writeFile1.open("student.txt", std::ios::app);writeFile.open("studentLogin.txt", std::ios::app);}writeFile << std::endl << act.toStdString() << " " << pwd.toStdString();writeFile1 << std::endl << act.toStdString() << " " << name.toStdString() << " " << gender.toStdString() << " " << department.toStdString() << " " << phone.toStdString();writeFile.close();writeFile1.close();QMessageBox::about(this, "注册成功", "快去登录系统吧");// 发射注册成功信号emit registrationSuccess();
}void RegistrationPage::onLoginButtonClicked()
{}// 设置控件字体和字号的函数
void RegistrationPage::setWidgetFont(QWidget* widget)
{QFont font;font.setFamily("宋体");font.setPointSize(16);widget->setFont(font);
}// 设置输入框宽度的函数
void RegistrationPage::setInputBoxWidth(QWidget* widget, int width)
{widget->setFixedWidth(width);
}// 创建带有指定样式的标签函数
QLabel* RegistrationPage::createStyledLabel(const QString& text)
{QLabel* label = new QLabel(text);setWidgetFont(label);return label;
}// 设置输入框字体和大小的函数
void RegistrationPage::setWidgetFontAndSize(QWidget* widget)
{QFont font;font.setFamily("宋体");font.setPointSize(16);widget->setFont(font);
}void RegistrationPage::setInputBoxHeight(QWidget* widget, int height)
{widget->setFixedHeight(height);
}

CAdministrator.cpp

cout<<需要完整源码,只需10<<endl;
cout<<源码+讲解,只需25元 需要请加位心:ch18384322303,备注:图书管理系统GUI源码<<endl;
cout<<讲解包括:<<endl;
cout<<项目讲解视频(如何运行,环境安装,代码思路等)、qt安装流程、qt安装包<<endl;
cout<<本项目问题答疑(不限次数)<<endl;

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/505392.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

云计算基础,虚拟化原理

文章目录 一、虚拟化1.1 什么是虚拟化1.2 虚拟化类型 二 、存储虚拟化2.1 存储指标2.2 存储类型2.3 存储协议2.4 RAID 三、内存 i/O虚拟化3.1 内存虚拟化基本概念地址空间转换原理内存共享与隔离原理 3.2 I/O 虚拟化基本概念模拟&#xff08;Emulation&#xff09;方式半虚拟化…

机器学习基础-概率图模型

&#xff08;一阶&#xff09;马尔科夫模型的基本概念 状态、状态转换概率、初始概率 状态转移矩阵的基本概念 隐马尔可夫模型&#xff08;HMM&#xff09;的基本概念 条件随机场&#xff08;CRF&#xff09;的基本概念 实际应用中的马尔科夫性 自然语言处理&#xff1a; 在词性…

设计模式学习[15]---适配器模式

文章目录 前言1.引例2.适配器模式2.1 对象适配器2.2 类适配器 总结 前言 这个模式其实在日常生活中有点常见&#xff0c;比如我们的手机取消了 3.5 m m 3.5mm 3.5mm的接口&#xff0c;只留下了一个 T y p e − C Type-C Type−C的接口&#xff0c;但是我现在有一个 3.5 m m 3.…

【简博士统计学习方法】第1章:2. 统计学习方法的基本分类

2. 统计学习方法的基本分类 监督学习所学习的数据都是已经标注过的&#xff1b;无监督学习所学习的数据没有标注信息&#xff1b;半监督学习只含有少量标注&#xff0c;大多数没有标注&#xff08;利用已标注的数据来学习去标注未标注的数据&#xff09; 2.1 监督学习 图里的…

Unity3d 基于Barracuda推理库和YOLO算法实现对象检测功能

前言 近年来&#xff0c;随着AI技术的发展&#xff0c;在游戏引擎中实现和运行机器学习模型的需求也逐渐显现。Unity3d引擎官方推出深度学习推理框架–Barracuda &#xff0c;旨在帮助开发者在Unity3d中轻松地实现和运行机器学习模型&#xff0c;它的主要功能是支持在 Unity 中…

IEC61850遥控-增强安全选控是什么?

摘要&#xff1a;遥控服务是IEC61850协议中非常重要的一项服务&#xff0c;其通常会被应用在电源开关、指示灯、档位调节等器件的操作。 遥控是一类比较特殊的操作&#xff0c;其通过远程方式操作指定的设备器件&#xff0c;在一些重要的场景中需要有严谨的机制来进行约束&…

[免费]微信小程序(高校就业)招聘系统(Springboot后端+Vue管理端)【论文+源码+SQL脚本】

大家好&#xff0c;我是java1234_小锋老师&#xff0c;看到一个不错的微信小程序(高校就业)招聘系统(Springboot后端Vue管理端)&#xff0c;分享下哈。 项目视频演示 【免费】微信小程序(高校就业)招聘系统(Springboot后端Vue管理端) Java毕业设计_哔哩哔哩_bilibili 项目介绍…

基于vue的商城小程序的毕业设计与实现(源码及报告)

环境搭建 ☞☞☞ ​​​Vue入手篇(一)&#xff0c;防踩雷(全网最详细教程)_vue force-CSDN博客 目录 一、功能介绍 二、登录注册功能 三、首页 四、项目截图 五、源码获取 一、功能介绍 用户信息展示&#xff1a;页面顶部设有用户头像和昵称展示区&#xff0c;方便用户识别…

IDEA配置maven和git并如何使用maven打包和git推送到gitlab

首先找到设置 在里面输入maven然后找到点击 然后点击右边两个选项 路径选择下载的maven目录下的settings文件和新建的repository文件夹 点击apply应用 然后在搜索框里搜git点击进去 此路径为git的exe执行文件所在目录&#xff0c;选好之后点击test测试下方出现git版本号表…

04、Redis深入数据结构

一、简单动态字符串SDS 无论是Redis中的key还是value&#xff0c;其基础数据类型都是字符串。如&#xff0c;Hash型value的field与value的类型&#xff0c;List型&#xff0c;Set型&#xff0c;ZSet型value的元素的类型等都是字符串。redis没有使用传统C中的字符串而是自定义了…

Python教程丨Python环境搭建 (含IDE安装)——保姆级教程!

工欲善其事&#xff0c;必先利其器。 学习Python的第一步不要再加收藏夹了&#xff01;提高执行力&#xff0c;先给自己装好Python。 1. Python 下载 1.1. 下载安装包 既然要下载Python&#xff0c;我们直接进入python官网下载即可 Python 官网&#xff1a;Welcome to Pyt…

springmvc前端传参,后端接收

RequestMapping注解 Target({ElementType.METHOD, ElementType.TYPE}) Retention(RetentionPolicy.RUNTIME) Documented Mapping public interface RequestMapping {String name() default "";AliasFor("path")String[] value() default {};AliasFor(&quo…

数据库环境安装(day1)

网址&#xff1a;MySQL 下载&#xff08;环境准备&#xff09;&#xff1a; &#xff08;2-5点击此处&#xff0c;然后选择合适的版本&#xff09; 1.linux在线YUM仓库 下载/安装: wget https://repo.mysql.com//mysql84-community-release-el9-1.noarch.rpm rpm -i https://r…

【MySQL系列文章】Linux环境下安装部署MySQL

前言 本次安装部署主要针对Linux环境进行安装部署操作,系统位数64 getconf LONG_BIT 64MySQL版本&#xff1a;v5.7.38 一、下载MySQL MySQL下载地址&#xff1a;MySQL :: Download MySQL Community Server (Archived Versions) 二、上传MySQL压缩包到Linuxx环境&#xff0c…

eNSP之家----ACL实验入门实例详解(Access Control List访问控制列表)(重要重要重要的事说三遍)

ACL实验&#xff08;Access Control List访问控制列表&#xff09;是一种基于包过滤的访问控制技术&#xff0c;它可以根据设定的条件对接口上的数据包进行过滤&#xff0c;允许其通过或丢弃。访问控制列表被广泛地应用于路由器和三层交换机。 准备工作 在eNSP里面部署设备&a…

web-app uniapp监测屏幕大小的变化对数组一行展示数据作相应处理

web-app uniapp监测屏幕大小的变化对数组一行展示数据作相应处理 1.uni.getSystemInfoSync().screenWidth; 获取屏幕宽度 2.uni.onWindowResize&#xff08;&#xff09; 实时监测屏幕宽度变化 3.根据宽度的大小拿到每行要展示的数量itemsPerRow 4.为了确保样式能够根据 items…

《零基础Go语言算法实战》【题目 1-14】字符串的替换

《零基础Go语言算法实战》 【题目 1-14】字符串的替换 请编写一个函数&#xff0c;将字符串中的空格全部替换为“%20”。假定该字符串有足够的空间存 放新增的字符&#xff0c;并且知道字符串的真实长度&#xff08;≤ 1000&#xff09;&#xff0c;同时保证字符串由大小写的…

WebSocket 测试入门篇

Websocket 是一种用于 H5 浏览器的实时通讯协议&#xff0c;可以做到数据的实时推送&#xff0c;可适用于广泛的工作环境&#xff0c;例如客服系统、物联网数据传输系统&#xff0c; 基础介绍 我们平常接触最多的是 http 协议的接口&#xff0c;http 协议是请求与响应的模式&…

音视频入门基础:MPEG2-PS专题(6)——FFmpeg源码中,获取PS流的视频信息的实现

音视频入门基础&#xff1a;MPEG2-PS专题系列文章&#xff1a; 音视频入门基础&#xff1a;MPEG2-PS专题&#xff08;1&#xff09;——MPEG2-PS官方文档下载 音视频入门基础&#xff1a;MPEG2-PS专题&#xff08;2&#xff09;——使用FFmpeg命令生成ps文件 音视频入门基础…

代码随想录算法训练营day27

代码随想录算法训练营 —day27 文章目录 代码随想录算法训练营前言一、贪心算法理论基础二、455.分发饼干三、376. 摆动序列53. 最大子数组和总结 前言 今天是算法营的第27天&#xff0c;希望自己能够坚持下来&#xff01; 今日任务&#xff1a; ● 贪心算法理论基础 ● 455.…