首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

2021_9_2Qt-main.zip

行业研究 3.22MB 13 需要积分: 1
立即下载

资源介绍:

2021_9_2Qt-main.zip
#include "server.h" #include "ui_server.h" #include #include #include #include #include #include int currentsize; server::server(QWidget *parent) : QMainWindow(parent) , ui(new Ui::server) { ui->setupUi(this); tcpServer = new QTcpServer(); ui->listWidget->clear(); ui->listWidget->insertItem(0,tr("当前无在线用户")); for(int i = 0; i < M; i++) { tcpSocket[i]=new QTcpSocket(); } tcpServer->listen(QHostAddress::Any,8888); //init db = QSqlDatabase::addDatabase("QSQLITE"); //判断是否建立了用户表 db.setDatabaseName("./people.db"); db.open(); QSqlQuery sqlquery; sqlquery.exec("CREATE TABLE if not exists people (id INTEGER NOT NULL UNIQUE,name TEXT NOT NULL UNIQUE,password TEXT NOT NULL,ip TEXT,islogin INTEGER NOT NULL,PRIMARY KEY(id AUTOINCREMENT))"); db.close(); connect(tcpServer,&QTcpServer::newConnection,[=](){ tcpSocket[0] = tcpServer->nextPendingConnection(); currentsize++; QString ip = tcpSocket[0]->peerAddress().toString().section(":",3,3); int port = tcpSocket[0]->peerPort(); //预留currentsize以用作多用户同时连接所用 QString str = QString("[%1:%2]").arg(ip).arg(port); qDebug() << str ; connect(tcpSocket[0],&QTcpSocket::readyRead,[=](){ //读取缓冲区数据 QByteArray buffer = tcpSocket[0]->readAll(); if("login" == QString(buffer).section("##",0,0)) {//登陆 db.setDatabaseName("./people.db"); db.open(); QSqlQuery sqlquery; sqlquery.prepare("select * from people where name = :name"); sqlquery.bindValue(":name",QString(buffer).section("##",1,1)); sqlquery.exec(); if(!sqlquery.next()) {//未查找到该用户 tcpSocket[0]->write(QString("login error##no_user").toUtf8()); tcpSocket[0]->flush(); db.close(); } else {//用户存在 int id = sqlquery.value(0).toInt(); QString pwd = sqlquery.value(2).toString(); if(pwd == QString(buffer).section("##",2,2)) {//登录成功 tcpSocket[0]->write(QString("login successed##%1").arg(id).toUtf8()); sqlquery.prepare("update people set ip=:ip, islogin=1 where name = :name"); sqlquery.bindValue(":ip",ip); sqlquery.bindValue(":name",QString(buffer).section("##",1,1)); sqlquery.exec(); tcpSocket[0]->flush(); //更新服务器界面 ui->listWidget->clear(); sqlquery.prepare("select * from people where islogin = 1"); sqlquery.exec(); if(sqlquery.next()) { QString userid = sqlquery.value(0).toString(); QString username = sqlquery.value(1).toString(); QString userip = sqlquery.value(3).toString(); //qDebug()<listWidget->insertItem(0,"用户ID:"+userid+",用户昵称:"+username+",用户IP:"+userip); int rownum = 1; while (sqlquery.next()) { QString userid = sqlquery.value(0).toString(); QString username = sqlquery.value(1).toString(); QString userip = sqlquery.value(3).toString(); ui->listWidget->insertItem(rownum,"用户ID:"+userid+",用户昵称:"+username+",用户IP:"+userip); rownum++; } } else { ui->listWidget->clear(); ui->listWidget->insertItem(0,tr("当前无在线用户")); } } else {//密码错误 tcpSocket[0]->write(QString("login error##errpwd").toUtf8()); tcpSocket[0]->flush(); db.close(); } } } else if("register" == QString(buffer).section("##",0,0)) {//注册环节 db.setDatabaseName("./people.db"); db.open(); QSqlQuery sqlquery; //注册用户的时候需要进行判重 sqlquery.prepare("select * from people where name = :name"); sqlquery.bindValue(":name",QString(buffer).section("##",1,1)); sqlquery.exec(); if(!sqlquery.next()) {//可以新建 sqlquery.clear(); sqlquery.prepare("insert into people values (null,:name,:password,null,0)"); sqlquery.bindValue(":name",QString(buffer).section("##",1,1)); sqlquery.bindValue(":password",QString(buffer).section("##",2,2)); sqlquery.exec(); sqlquery.clear(); sqlquery.prepare("select * from people where name = :name"); sqlquery.bindValue(":name",QString(buffer).section("##",1,1)); sqlquery.exec();//获得新建的用户的id sqlquery.next(); int newid = sqlquery.value(0).toInt(); sqlquery.exec("create table if not exists friend__" + QString::number(newid) +"(id INTEGER unique, name TEXT,sendmassage INTEGER,sendfile INTEGER)"); tcpSocket[0]->write(QString("register successed").toUtf8()); tcpSocket[0]->flush(); db.close(); } else {//有重名 tcpSocket[0]->write(QString("register error##same_name").toUtf8()); tcpSocket[0]->flush(); db.close(); } } else if("wantsendmessage" == QString(buffer).section("##",0,0)) {//想发信息,校验有没有这个人 db.setDatabaseName("./people.db"); db.open(); QSqlQuery sqlquery; sqlquery.prepare("select * from people where name = :name"); sqlquery.bindValue(":name",QString(buffer).section("##",2,2)); sqlquery.exec(); if(sqlquery.next()) {//有这个人在,可以发消息 int otherid = sqlquery.value(0).toInt(); tcpSocket[0]->write(QString("wantsendmessage_ok##%1").arg(otherid).toUtf8()); tcpSocket[0]->flush(); //发消息前把数据库准备好 int thisid = QString(buffer).section("##",1,1).toInt(); if(thisid < otherid) { sqlquery.exec("CREATE TABLE if not exists chat__" + QString::number(thisid) + "__" + QString::number(otherid) + "(time datetime NOT NULL UNIQUE,id INTEGER,message TEXT, PRIMARY KEY(time))"); } else { sqlquery.exec("CREATE TABLE if not exists chat__" + QString::number(otherid) + "__" + QString::number(thisid) + "(time datetime NOT NULL UNIQUE,id INTEGER,message TEXT, PRIMARY KEY(time))"); } db.close(); }

资源文件列表:

2021_9_2Qt-main.zip 大约有81个文件
  1. 2021_9_2Qt-main/
  2. 2021_9_2Qt-main/client/
  3. 2021_9_2Qt-main/client/.DS_Store 6KB
  4. 2021_9_2Qt-main/client/Client.qrc 1.73KB
  5. 2021_9_2Qt-main/client/QT/
  6. 2021_9_2Qt-main/client/QT/icon/
  7. 2021_9_2Qt-main/client/QT/icon/Add.png 8.04KB
  8. 2021_9_2Qt-main/client/QT/icon/AddAccount.png 6.28KB
  9. 2021_9_2Qt-main/client/QT/icon/Back.png 7.79KB
  10. 2021_9_2Qt-main/client/QT/icon/BackGround_4.jpg 678.33KB
  11. 2021_9_2Qt-main/client/QT/icon/Back_purple.png 6.45KB
  12. 2021_9_2Qt-main/client/QT/icon/Background_1.jpg 654.44KB
  13. 2021_9_2Qt-main/client/QT/icon/Background_2.jpg 362.79KB
  14. 2021_9_2Qt-main/client/QT/icon/Background_3.jpg 755.05KB
  15. 2021_9_2Qt-main/client/QT/icon/Background_5.jpg 313.03KB
  16. 2021_9_2Qt-main/client/QT/icon/Background_6.jpg 374.89KB
  17. 2021_9_2Qt-main/client/QT/icon/Chat.png 8.26KB
  18. 2021_9_2Qt-main/client/QT/icon/Chat_icon.png 4.06KB
  19. 2021_9_2Qt-main/client/QT/icon/Closed.png 9.62KB
  20. 2021_9_2Qt-main/client/QT/icon/Delete.png 5.21KB
  21. 2021_9_2Qt-main/client/QT/icon/File.png 3.42KB
  22. 2021_9_2Qt-main/client/QT/icon/Login.png 5.75KB
  23. 2021_9_2Qt-main/client/QT/icon/LoginOut_blue.png 4.67KB
  24. 2021_9_2Qt-main/client/QT/icon/Login_Blue.png 4.64KB
  25. 2021_9_2Qt-main/client/QT/icon/Login_Red.png 6.77KB
  26. 2021_9_2Qt-main/client/QT/icon/Login_lightBlue.png 3.15KB
  27. 2021_9_2Qt-main/client/QT/icon/Logout.png 5.51KB
  28. 2021_9_2Qt-main/client/QT/icon/Me.png 6.85KB
  29. 2021_9_2Qt-main/client/QT/icon/Message.png 6.73KB
  30. 2021_9_2Qt-main/client/QT/icon/More Circle.png 7.5KB
  31. 2021_9_2Qt-main/client/QT/icon/Password.png 6.62KB
  32. 2021_9_2Qt-main/client/QT/icon/Refresh.png 7.13KB
  33. 2021_9_2Qt-main/client/QT/icon/Register.png 4.71KB
  34. 2021_9_2Qt-main/client/QT/icon/Search.png 5.7KB
  35. 2021_9_2Qt-main/client/QT/icon/Send.png 6.29KB
  36. 2021_9_2Qt-main/client/QT/icon/SendFile.png 7.29KB
  37. 2021_9_2Qt-main/client/QT/icon/SendFile_blue.png 7.84KB
  38. 2021_9_2Qt-main/client/QT/icon/SlectFile.png 8.84KB
  39. 2021_9_2Qt-main/client/QT/icon/confirPwd_green.png 7.87KB
  40. 2021_9_2Qt-main/client/QT/icon/go.png 9.95KB
  41. 2021_9_2Qt-main/client/QT/icon/login_Account.png 6.72KB
  42. 2021_9_2Qt-main/client/QT/icon/login_密码.png 4.63KB
  43. 2021_9_2Qt-main/client/QT/icon/name_green.png 4.51KB
  44. 2021_9_2Qt-main/client/QT/icon/name_lightgreen.png 7.79KB
  45. 2021_9_2Qt-main/client/QT/icon/password_green.png 6.95KB
  46. 2021_9_2Qt-main/client/QT/icon/talk.png 12.27KB
  47. 2021_9_2Qt-main/client/QT/icon/toRight.png 8.2KB
  48. 2021_9_2Qt-main/client/VolumeConfiguration.plist 4.35KB
  49. 2021_9_2Qt-main/client/chatdialog.cpp 4.32KB
  50. 2021_9_2Qt-main/client/chatdialog.h 587B
  51. 2021_9_2Qt-main/client/chatdialog.ui 4.16KB
  52. 2021_9_2Qt-main/client/client.cpp 3.61KB
  53. 2021_9_2Qt-main/client/client.h 704B
  54. 2021_9_2Qt-main/client/client.pro 997B
  55. 2021_9_2Qt-main/client/client.pro.user 22.52KB
  56. 2021_9_2Qt-main/client/client.ui 11.29KB
  57. 2021_9_2Qt-main/client/clientserve.cpp 2.51KB
  58. 2021_9_2Qt-main/client/clientserve.h 415B
  59. 2021_9_2Qt-main/client/clientserve.ui 392B
  60. 2021_9_2Qt-main/client/home.cpp 17.33KB
  61. 2021_9_2Qt-main/client/home.h 782B
  62. 2021_9_2Qt-main/client/home.ui 17.18KB
  63. 2021_9_2Qt-main/client/main.cpp 163B
  64. 2021_9_2Qt-main/client/receivefiledialog.cpp 3.62KB
  65. 2021_9_2Qt-main/client/receivefiledialog.h 640B
  66. 2021_9_2Qt-main/client/receivefiledialog.ui 3.61KB
  67. 2021_9_2Qt-main/client/registerdialog.cpp 4.17KB
  68. 2021_9_2Qt-main/client/registerdialog.h 880B
  69. 2021_9_2Qt-main/client/registerdialog.ui 13.77KB
  70. 2021_9_2Qt-main/client/sendfiledialog.cpp 4KB
  71. 2021_9_2Qt-main/client/sendfiledialog.h 774B
  72. 2021_9_2Qt-main/client/sendfiledialog.ui 6.04KB
  73. 2021_9_2Qt-main/client/userinfo.cpp 147B
  74. 2021_9_2Qt-main/client/userinfo.h 246B
  75. 2021_9_2Qt-main/server/
  76. 2021_9_2Qt-main/server/.DS_Store 6KB
  77. 2021_9_2Qt-main/server/main.cpp 164B
  78. 2021_9_2Qt-main/server/server.cpp 22.38KB
  79. 2021_9_2Qt-main/server/server.h 542B
  80. 2021_9_2Qt-main/server/server.pro 602B
  81. 2021_9_2Qt-main/server/server.ui 1.18KB
0评论
提交 加载更多评论
其他资源 单片机基础仿真与创客拓展99.zip
单片机基础仿真与创客拓展99.zip
单片机基础仿真与创客拓展99.zip 单片机基础仿真与创客拓展99.zip
Mini-Omni:语言模型可以在流式传输中聆听、交谈和思考
Mini-Omni 是一个开源多模型大型语言模型,可以一边听、一边说,一边思考。具有实时端到端语音输入和流音频输出对话功能。 特征 实时语音对话功能。无需额外的 ASR 或 TTS 模型。 一边说话一边思考,能够同时生成文本和音频。 流音频输出功能。 通过“音频到文本”和“音频到音频”批量推理进一步提升性能。
Mini-Omni:语言模型可以在流式传输中聆听、交谈和思考
dlib-19.17.0-cp37-cp37m-win-amd64.whl
dlib-19.17.0-cp37-cp37m-win_amd64.whl 记得解压记得解压
撮合交易的购售双方申报信息及节点通道信息
算例,节点间连接关系,撮合交易申报信息
Android阶段性学习成果
基于Java的Android studio开发的一款简易的App。 采用MVP架构 有用户登录以及内容编辑和工具设置界面 设计简易
Android阶段性学习成果 Android阶段性学习成果 Android阶段性学习成果
人脸识别模型,解压后放置到工程public文件夹下
人脸识别模型,解压后放置到工程public文件夹下
栈的介绍,应用及基础例题
程序=数据结构+算法,数据结构是对 ADT 的实现,而栈是数据的逻辑结构中的线性结构,也是需要掌握的,本篇主要讲的就是栈的介绍,它的基础用法及一些例题,能够帮助想要学数据结构的新手们快速入门,当然如果你对栈已经有一些基础了解并能够完成一些基础例题,看不看这篇文章都是可以的。
栈的介绍,应用及基础例题 栈的介绍,应用及基础例题 栈的介绍,应用及基础例题
简易博客网站设计(Spring boot)
简易博客网站设计