【QT】day6

在这里插入图片描述

#include "home.h"
#include "ui_home.h"Home::Home(QWidget *parent): QWidget(parent), ui(new Ui::Home)
{ui->setupUi(this);// 从配置文件读取用户名QSettings settings("kim", "ad");username = settings.value("username").toString();usertype = settings.value("usertype").toString();ui->usertypelabel->setText(usertype);if(usertype=="学生"){ui->listframe->hide();ui->setframe->hide();ui->mainframe->hide();QFrame *stuframe = new QFrame();stuframe->setParent(this);stuframe->setStyleSheet("width:100px;height:100px;background-color: rgb(250, 250, 250);");stuframe->move(100,0);teachEdit = new QLineEdit(this);teachEdit->move(200,50);teachEdit->setStyleSheet("background-color:#ffffff;color:#000000;width:200px;height:30px;border-radius:7px;color:#000000;padding-left:10px;");teachEdit->setPlaceholderText("请输入教师账号");adkeyEdit = new QLineEdit(this);adkeyEdit->move(200,90);adkeyEdit->setStyleSheet("background-color:#ffffff;color:#000000;width:200px;height:30px;border-radius:7px;color:#000000;padding-left:10px;");adkeyEdit->setPlaceholderText("请输入签到验证码");adkeybtn = new QPushButton(this);adkeybtn->move(200,170);adkeybtn->setText("签到");adkeybtn->setStyleSheet("background-color:#000000;color:#ffffff;width:200px;height:40px;border-radius:7px;");connect(adkeybtn, &QPushButton::clicked, this, &Home::onAdKeyBtnClicked);stuHintLable = new QLabel(this);stuHintLable->move(210,140);stuHintLable->setFixedWidth(200);stuHintLable->setStyleSheet("color:rgb(222, 60, 51);height:40px;");}ui->usernamelabel->setText(username);ui->usertypelabel->setAlignment(Qt::AlignCenter);closeAllpage();openAdPage();
}Home::~Home()
{delete ui;
}void Home::onAdKeyBtnClicked() {if(teachEdit->text()==""){stuHintLable->setText("教师账号不能为空");stuHintLable->setStyleSheet("color:rgb(222, 60, 51);height:40px;");}else if(adkeyEdit->text()==""){stuHintLable->setText("签到激活码不能为空");stuHintLable->setStyleSheet("color:rgb(222, 60, 51);height:40px;");}else{socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::stuad_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::stuad_readyRead_slot);}}void Home::startad_connected_slot()
{struct data user;user.type=STARTAD;user.username=username;user.value=generateRandomString(6);ui->hintlable_3->setText("签到码:"+user.value);ui->startattendancebtn->setStyleSheet("background-color:#ffffff;border-radius:7px;border:1px solid #000000;color:#000000;");socket->write(user.toByteArray());
}void Home::startad_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));outputlog(receivedInfo.data);socket->disconnectFromHost();
}void Home::endad_connected_slot()
{struct data user;user.type=ENDAD;user.username=username;user.value="123";ui->hintlable_3->setText("");ui->startattendancebtn->setStyleSheet("background-color:#000000;border-radius:7px;color:#ffffff;");socket->write(user.toByteArray());
}void Home::endad_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));outputlog(receivedInfo.data);socket->disconnectFromHost();
}void Home::addname_connected_slot()
{struct data user;user.type=NAMEADD;user.username=username;user.value=ui->funcinput->text();socket->write(user.toByteArray());
}void Home::addname_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));outputlog("【"+ui->funcinput->text()+"】"+receivedInfo.data);ui->funcinput->clear();socket->disconnectFromHost();
}void Home::getAllName_connected_slot()
{struct data user;user.type=NAMEGETALL;user.username=username;user.value="123";socket->write(user.toByteArray());
}void Home::getAllName_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));QString receivedData(receivedInfo.data);QStringList records = receivedData.split("|", Qt::SkipEmptyParts);// 遍历每个记录ui->settable->setRowCount(records.size());for (int row = 0; row < records.size(); ++row) {// 以 '\n' 分割记录中的行QStringList lines = records[row].split("\n", Qt::SkipEmptyParts);// 遍历每行并添加到QTableWidget中for (int col = 0; col < lines.size(); ++col) {// 以 ':' 分割键和值QStringList keyValue = lines[col].split("&", Qt::SkipEmptyParts);QString key = keyValue[0].trimmed();QString value = keyValue[1].trimmed();QTableWidgetItem *item = new QTableWidgetItem(value);ui->settable->setItem(row, col, item);item->setTextAlignment(Qt::AlignCenter);}}ui->settable->setColumnWidth(0, 50);ui->settable->setColumnWidth(1, 100);ui->settable->setColumnWidth(2, 180);socket->disconnectFromHost();
}void Home::deletename_connected_slot()
{QList<QTableWidgetItem *> selectedItems = ui->settable->selectedItems();if (!selectedItems.isEmpty()) {int selectedRow = selectedItems.first()->row();QTableWidgetItem *item1 = ui->settable->item(selectedRow, 0);QString content1 = item1->text();struct data user;user.type=NAMEDELETE;user.username=username;user.value=content1;socket->write(user.toByteArray());} else {qDebug() << "No row selected.";}
}void Home::deletename_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));outputlog(receivedInfo.data);socket->disconnectFromHost();
}void Home::searchname_connected_slot()
{struct data user;user.type=NAMESEARCH;user.username=username;user.value=ui->funcinput->text();socket->write(user.toByteArray());
}void Home::searchname_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));QString receivedData(receivedInfo.data);QStringList records = receivedData.split("|", Qt::SkipEmptyParts);// 遍历每个记录ui->settable->setRowCount(records.size());for (int row = 0; row < records.size(); ++row) {// 以 '\n' 分割记录中的行QStringList lines = records[row].split("\n", Qt::SkipEmptyParts);// 遍历每行并添加到QTableWidget中for (int col = 0; col < lines.size(); ++col) {// 以 ':' 分割键和值QStringList keyValue = lines[col].split("&", Qt::SkipEmptyParts);QString key = keyValue[0].trimmed();QString value = keyValue[1].trimmed();QTableWidgetItem *item = new QTableWidgetItem(value);ui->settable->setItem(row, col, item);item->setTextAlignment(Qt::AlignCenter);}}ui->settable->setColumnWidth(0, 50);ui->settable->setColumnWidth(1, 100);ui->settable->setColumnWidth(2, 180);socket->disconnectFromHost();
}void Home::getadList_connected_slot()
{struct data user;user.type=NAMEHISTORY;user.username=username;user.value="123";socket->write(user.toByteArray());
}void Home::getadList_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));QString receivedData(receivedInfo.data);QStringList records = receivedData.split("|", Qt::SkipEmptyParts);// 遍历每个记录ui->settable->setRowCount(records.size());for (int row = 0; row < records.size(); ++row) {// 以 '\n' 分割记录中的行QStringList lines = records[row].split("\n", Qt::SkipEmptyParts);// 遍历每行并添加到QTableWidget中for (int col = 0; col < lines.size(); ++col) {// 以 ':' 分割键和值QStringList keyValue = lines[col].split("&", Qt::SkipEmptyParts);QString key = keyValue[0].trimmed();QString value = keyValue[1].trimmed();QTableWidgetItem *item = new QTableWidgetItem(value);ui->settable->setItem(row, col, item);item->setTextAlignment(Qt::AlignCenter);}}ui->settable->setColumnWidth(0, 50);ui->settable->setColumnWidth(1, 80);ui->settable->setColumnWidth(2, 80);ui->settable->setColumnWidth(3, 160);socket->disconnectFromHost();
}void Home::stuad_connected_slot()
{struct data user;user.type=STUAD;user.username=username;user.value=teachEdit->text();user.value1=adkeyEdit->text();socket->write(user.toByteArray());
}void Home::callname_connected_slot()
{struct data user;user.type=NAMECALL;user.username=username;user.value="123";user.value1="123";socket->write(user.toByteArray());
}void Home::callname_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));outputlog(receivedInfo.data);socket->disconnectFromHost();
}void Home::stuad_readyRead_slot()
{QByteArray rawData = socket->readAll();const char* rawCharArray = rawData.constData();socketinfo receivedInfo;memcpy(&receivedInfo, rawCharArray, sizeof(socketinfo));stuHintLable->setText(receivedInfo.data);stuHintLable->setStyleSheet("color:rgb(26, 136, 35);height:40px;");socket->disconnectFromHost();
}void Home::on_startattendancebtn_clicked()
{if(ui->startattendancebtn->text()=="发起签到"){socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::startad_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::startad_readyRead_slot);ui->startattendancebtn->setText("关闭签到");}else{socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::endad_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::endad_readyRead_slot);ui->startattendancebtn->setText("发起签到");ui->startattendancebtn->setStyleSheet("background-color:#000000;border-radius:7px;color:#ffffff;");}}void Home::outputlog(QString msg)
{ui->adEdit->setText("【"+getCurretTime()+"】"+msg+"\n"+ui->adEdit->toPlainText());
}QString Home::getCurretTime()
{QTime systime = QTime::currentTime();QString s = systime.toString("hh:mm:ss");return s;
}QString Home::generateRandomString(int length) {const QString charset = "123456789abcdefghijklmnpqrstuvwxyz";QString randomString;for (int i = 0; i < length; ++i) {int randomIndex = QRandomGenerator::global()->bounded(charset.length());randomString.append(charset.at(randomIndex));}return randomString;
}void Home::closeAllpage()
{ui->hintframe->hide();ui->hintframe_2->hide();ui->startattendancebtn->hide();ui->setmainframe->hide();ui->callnamebtn->hide();
}void Home::openAdPage()
{ui->hintframe->show();ui->hintframe_2->show();ui->startattendancebtn->show();ui->callnamebtn->show();this->setWindowTitle("签到管理系统v1.0-签到");
}void Home::openListPage()
{this->setWindowTitle("签到管理系统v1.0-记录");ui->setmainframe->show();ui->funcinput->hide();ui->addbtn->hide();ui->searchbtn->hide();ui->deletebtn->hide();ui->backbtn->hide();QStringList headerLabels;headerLabels << "ID" << "姓名" << "签到码" << "签到时间";ui->settable->setHorizontalHeaderLabels(headerLabels);ui->settable->verticalHeader()->setVisible(false);ui->settable->setColumnCount(4);ui->settable->setStyleSheet("QScrollBar:vertical {""    background: #ffffff;""    width: 10px;""    margin: 16px 0px 16px 0px;""}""QScrollBar::handle:vertical {""    background: rgb(78, 79, 79);""    min-height: 10px;""}""QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {""    border: none;""    background: none;""}""QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {""    background: none;""}""#settable{background-color:#ffffff;color:#000000;}""QTableWidget::item:selected {""    background-color: #eeeeee;""color:#000000;""}");socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::getadList_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::getadList_readyRead_slot);for (int row = 0; row < ui->settable->rowCount(); ++row) {for (int col = 0; col < ui->settable->columnCount(); ++col) {QTableWidgetItem *item = new QTableWidgetItem(QString("Row %1, Col %2").arg(row + 1).arg(col + 1));// 设置文本居中item->setTextAlignment(Qt::AlignCenter);}}
}void Home::openSetPage()
{this->setWindowTitle("签到管理系统v1.0-设置");ui->setmainframe->show();ui->funcinput->show();ui->addbtn->show();ui->searchbtn->show();ui->deletebtn->show();ui->backbtn->show();QStringList headerLabels;headerLabels << "ID" << "姓名" << "添加时间";ui->settable->setHorizontalHeaderLabels(headerLabels);ui->settable->verticalHeader()->setVisible(false);ui->settable->setColumnCount(3);ui->settable->setColumnWidth(2, 500);ui->settable->setStyleSheet("QScrollBar:vertical {""    background: #ffffff;""    width: 10px;""    margin: 16px 0px 16px 0px;""}""QScrollBar::handle:vertical {""    background: rgb(78, 79, 79);""    min-height: 10px;""}""QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical {""    border: none;""    background: none;""}""QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {""    background: none;""}""#settable{background-color:#ffffff;color:#000000;}""QTableWidget::item:selected {""    background-color: #eeeeee;""color:#000000;""}");socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::getAllName_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::getAllName_readyRead_slot);for (int row = 0; row < ui->settable->rowCount(); ++row) {for (int col = 0; col < ui->settable->columnCount(); ++col) {QTableWidgetItem *item = new QTableWidgetItem(QString("Row %1, Col %2").arg(row + 1).arg(col + 1));// 设置文本居中item->setTextAlignment(Qt::AlignCenter);}}}void Home::on_callbtn_2_clicked()
{closeAllpage();openListPage();
}void Home::on_callbtn_clicked()
{closeAllpage();openAdPage();
}void Home::on_callbtn_3_clicked()
{closeAllpage();openSetPage();
}void Home::on_callnamebtn_clicked()
{socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::callname_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::callname_readyRead_slot);
}void Home::on_addbtn_clicked()
{socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::addname_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::addname_readyRead_slot);
}void Home::on_deletebtn_clicked()
{socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::deletename_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::deletename_readyRead_slot);}void Home::on_backbtn_clicked()
{// 创建 Widget 窗口Widget *w = new Widget();// 显示 Widget 窗口w->show();// 关闭当前 Home 窗口this->close();
}void Home::on_searchbtn_clicked()
{socket = new QTcpSocket(this);socket->connectToHost(ip,port);connect(socket,&QTcpSocket::connected,this,&Home::searchname_connected_slot);connect(socket,&QTcpSocket::readyRead,this,&Home::searchname_readyRead_slot);
}

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

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

相关文章

K8S之运用亲和性设置Pod的调度约束

亲和性 Node节点亲和性硬亲和实践软亲和性实践 Pod节点亲和性和反亲和性pod亲和性硬亲和实践 pod反亲和性 Pod 的yaml文件里 spec 字段中包含一个 affinity 字段&#xff0c;使用一组亲和性调度规则&#xff0c;指定pod的调度约束。 kubectl explain pods.spec.affinity 配置…

Spring第二天

一、第三方资源配置管理 说明&#xff1a;以管理DataSource连接池对象为例讲解第三方资源配置管理 1 管理DataSource连接池对象 问题导入 配置数据库连接参数时&#xff0c;注入驱动类名是用driverClassName还是driver&#xff1f; 1.1 管理Druid连接池【重点】 数据库准备…

Mybatis是否支持延迟加载?

前言 随着互联网应用的不断发展&#xff0c;数据库访问成为了应用开发中的一个重要环节。在这个背景下&#xff0c;MyBatis作为一种优秀的持久层框架&#xff0c;提供了灵活的SQL映射配置和强大的功能&#xff0c;为开发者提供了便捷的数据库访问解决方案。本文将深入探讨MyBat…

Optimism为 CQT提供价值 20 万美元的生态系统资助,以表彰其支持

Covalent Network&#xff08;CQT&#xff09; 是 Web3 生态系统中关键的“数据可用性”层&#xff0c;在与 Optimism Collective 多年的合作中取得了骄人的成果。Covalent Network&#xff08;CQT&#xff09;对于 Optimism 跨链数据的增长产生了直接的影响&#xff0c;而这一…

Unity类银河恶魔城学习记录5-1.5-2 P62-63 Creating Player Manager and Skill Manager源代码

Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释&#xff0c;可供学习Alex教程的人参考 此代码仅为较上一P有所改变的代码 【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili PlayerManager.cs using System.Collections; using System.Collections.G…

读千脑智能笔记08_人工智能的未来(下)

1. 机器智能存在的风险 1.1. “人工智能”这个名字应用到几乎所有涉及机器学习的领域 1.2. 技术专家对人工智能的态度也从“人工智能可能永远不会实现”快速转变为“人工智能可能在不久的将来毁灭所有人类” 1.3. 每一项新技术都可能会被滥用…

UE4运用C++和框架开发坦克大战教程笔记(十九)(第58~60集)完结

UE4运用C和框架开发坦克大战教程笔记&#xff08;十九&#xff09;&#xff08;第58~60集&#xff09;完结 58. 弹窗显示与隐藏59. UI 面板销毁60. 框架完成与总结 58. 弹窗显示与隐藏 这节课我们先来补全 TransferMask() 里对于 Overlay 布局类型面板的遮罩转移逻辑&#xff…

华为第二批难题五:AI技术提升六面体网格生成自动化问题

有CAE开发商问及OCCT几何内核的网格方面的技术问题。其实&#xff0c;OCCT几何内核的现有网格生成能力比较弱。 HybridOctree_Hex的源代码&#xff0c;还没有仔细去学习。 “HybridOctree_Hex”的开发者说&#xff1a;六面体网格主要是用在数值模拟领域的&#xff0c;比如汽车…

第十六篇【传奇开心果系列】Python的OpenCV库技术点案例示例:图像质量评估

传奇开心果短博文系列 系列短博文目录Python的OpenCV库技术点案例示例短博文系列博文目录前言一、图像质量评估方法和相关函数的介绍二、均方误差示例代码三、峰值信噪比示例代码四、结构相似性指数示例代码五、视频质量评估示例代码六、OpenCV均方根误差计算示例代码七、OpenC…

Go语言每日一题——链表篇(七)

传送门 牛客面试笔试必刷101题 ----------------删除链表的倒数第n个节点 题目以及解析 题目 解题代码及解析 解析 这一道题与昨天的题目在解题思路上有一定的相似之处&#xff0c;都是基于双指针定义快慢指针&#xff0c;这里我们让快指针先走n步&#xff0c;又因为n一定…

WebSocket+Http实现功能加成

WebSocketHttp实现功能加成 前言 首先&#xff0c;WebSocket和HTTP是两种不同的协议&#xff0c;它们在设计和用途上有一些显著的区别。以下是它们的主要特点和区别&#xff1a; HTTP (HyperText Transfer Protocol): 请求-响应模型&#xff1a; HTTP 是基于请求-响应模型的协…

监督学习 - 逻辑回归(Logistic Regression)

什么是机器学习 逻辑回归&#xff08;Logistic Regression&#xff09;虽然名字中包含"回归"一词&#xff0c;但实际上是一种用于解决分类问题的统计学习方法&#xff0c;而不是回归问题。它是一种线性模型&#xff0c;常用于二分类问题&#xff0c;也可以扩展到多分…