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

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

源代码·Qt/C++使用小记9

后端 42.98MB 20 需要积分: 1
立即下载

资源介绍:

Qt/C++使用小记9【使用UDP创建连接发送消息/传输单个文件】
#include "Widget.h" #include "ui_Widget.h" #include #include #include #include #include #include Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget), m_udpSocket(nullptr), m_strFilePath(""), m_bRecevieFile(false), m_uFileStatus(Default_Status), m_strReceviePath("") { ui->setupUi(this); // 实例化对象 m_udpSocket = new MyCustomUdpSocket; // 绑定接受数据的信号与槽 connect(m_udpSocket, &MyCustomUdpSocket::SignalRecevieData, this, &Widget::SlotRecevieShowData); // 初始化连接状态未连接为红色 连接上了则为绿色 通过心跳判定 // 心跳规定为3秒一次 若四秒内没有收到心跳 置为未连接 ui->label_status->setStyleSheet("color:red;"); // 绑定timer connect(&m_timer, &QTimer::timeout, this, [=]{ ui->label_status->setStyleSheet("color:red;"); ui->label_status->setText(u8"未连接"); }); } Widget::~Widget() { // 释放 DELETE_OBJ(m_udpSocket); delete ui; } /** * @brief on_pushButton_bind_clicked 绑定按钮点击槽函数 */ void Widget::on_pushButton_bind_clicked() { // 判断是否绑定,若已绑定不能重复绑定 if(u8"断开绑定" == ui->pushButton_bind->text()) { // 断开绑定 m_udpSocket->BreakBind(); qDebug()<<__FUNCTION__<GetConnectStatus(); // 设置ui ui->pushButton_bind->setText(u8"绑定"); ui->pushButton_bind->setStyleSheet("color:black;"); } else { //先进行绑定并获取返回值 bool flag = m_udpSocket->SetHostUdpInfo(ui->lineEdit_host_Addr->text(), ui->lineEdit_host_port->text().toInt()); //判断返回值是否绑定成功(为修改按钮文本和发送IP和端口号) if(!flag) { //未绑定成功则在浏览框中提示然后返回 ui->textBrowser->append(u8"未绑定成功,请确认IP或端口号是否正确!" + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); return; } else { ui->textBrowser->append(u8"绑定成功!" + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); } // 打印当前绑定信息 qDebug()<<__FUNCTION__<GetConnectStatus(); //更改按钮文本 ui->pushButton_bind->setText(u8"断开绑定"); ui->pushButton_bind->setStyleSheet("color:red;"); //发送IP和端口号信息 m_udpSocket->SetTargetUdpInfo(ui->lineEdit_target_addr->text(), ui->lineEdit_target_prot->text().toUShort()); } } /** * @brief Widget::on_pushButton_send_message_clicked 发送消息按钮槽函数 */ void Widget::on_pushButton_send_message_clicked() { // 如果为未绑定状态 if(m_udpSocket->GetConnectStatus() == QAbstractSocket::UnconnectedState) { ui->textBrowser->append(u8"网络未连接 " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); } else if(m_udpSocket->GetConnectStatus() == QAbstractSocket::BoundState) // 为绑定状态 { // 获取界面输入的信息 QString strData = ui->textEdit->toPlainText(); if(strData.isEmpty()) return; ui->textBrowser->append(u8"我 " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); ui->textBrowser->append(" " + strData); // 调用接口发送数据 统一编码格式为utf8发送 m_udpSocket->SendData(strData.toUtf8()); } else { // 若为其他状态 则打印连接状态 qDebug()<<__FUNCTION__<GetConnectStatus(); } } /** * @brief SlotRecevieShowData 接收数据并显示槽函数 * @param strData 具体内容 */ void Widget::SlotRecevieShowData(const QByteArray &strData) { // 如果信息内容为宏定义的标识符 为开始传输文件 "START_SENDFILE" if(QString::fromUtf8(strData) == START_SEND_FILE) { // 接收文件置true m_bRecevieFile = true; // 接收状态改为处理文件名字 m_uFileStatus = Handle_FileName_Status; return; } // 如果信息内容为宏定义的标识符 为结束传输文件 "END_SENDFILE" if(QString::fromUtf8(strData) == END_SEND_FILE) { // 重置接受文件状态 // 正在接收文件置否 m_bRecevieFile = false; // 文件处理步骤置为初始状态 m_uFileStatus = Default_Status; // 显示接收文件完成信息 QStringList strList = m_strReceviePath.split("/"); ui->textBrowser->append(u8"接收文件: " + strList.last() + u8" 完成 " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); // 接收文件路径置空 m_strReceviePath = ""; return; } // 判断文件处理状态 switch(m_uFileStatus) { case Handle_FileName_Status: { // 文件放在根目录的RecevieFile文件夹下 QDir dir; if(!dir.exists("./RecevieFile")) { bool b = dir.mkpath("./RecevieFile"); if(!b) qDebug() << "Failed to create folder:" << "./RecevieFile"; } const QString strFilePath = "./RecevieFile/" + QString::fromUtf8(strData); ui->textBrowser->append(u8"开始接收文件: " + QString::fromUtf8(strData) + " " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); // 保存文件的路径和文件名 m_strReceviePath = strFilePath; // 改变接收文件状态为处理文件数据 m_uFileStatus = Handle_FileData_Status; return; } case Handle_FileData_Status: { // 创建QFile QFile file(m_strReceviePath); // 用只写和追加写入 if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) { // 若创建或者打开失败 显示失败信息并置为初始状态 qDebug() << "Failed to create file" << m_strReceviePath; m_uFileStatus = Default_Status; m_bRecevieFile = false; ui->textBrowser->append(u8"接收文件: " + m_strReceviePath + u8" 失败 " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); m_strReceviePath = ""; return; } // 写入文件 file.write(strData.data(), strData.size()); file.close(); } default: break; } // 判断文件处理状态 // 若不为接收文件状态 则正常接收消息 if(m_bRecevieFile == false) { // 如果信息不为空 if(!strData.isEmpty()) { // 过滤掉心跳信息 if(QString::fromUtf8(strData) != HEARTBEAT_INFO) { ui->textBrowser->append(u8"对方 " + QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")); ui->textBrowser->append(" " + QString::fromUtf8(strData)); } else // 处理心跳信息 { // 收到心跳就暂停计时 m_timer.stop(); // 开启新一轮计时4秒间隔 m_timer.start(JUDGMENT_BREAK_LINK_SPACE); ui->label_status->setText(u8"已连接"); ui->label_status->setStyleSheet("color:green;"); } } } } /** * @brief on_pushButton_choose_file_clicked 选择文件按钮槽函数 */ void Widget::on_pushButton_choose_file_clicked() { // 获取打开窗口的文件的路径 QS

资源文件列表:

TestProject.zip 大约有113个文件
  1. TestProject/
  2. TestProject/Bin/
  3. TestProject/Bin/Debug_64/
  4. TestProject/Bin/Debug_64/D3Dcompiler_47.dll 3.98MB
  5. TestProject/Bin/Debug_64/Qt5Cored.dll 12.52MB
  6. TestProject/Bin/Debug_64/Qt5Guid.dll 13.14MB
  7. TestProject/Bin/Debug_64/Qt5Networkd.dll 3.22MB
  8. TestProject/Bin/Debug_64/Qt5Svgd.dll 708KB
  9. TestProject/Bin/Debug_64/Qt5Widgetsd.dll 11.02MB
  10. TestProject/Bin/Debug_64/TidyUpQtProjectd.exe 179KB
  11. TestProject/Bin/Debug_64/TidyUpQtProjectd.ilk 2.19MB
  12. TestProject/Bin/Debug_64/TidyUpQtProjectd.pdb 2.91MB
  13. TestProject/Bin/Debug_64/bearer/
  14. TestProject/Bin/Debug_64/bearer/qgenericbearerd.dll 170KB
  15. TestProject/Bin/Debug_64/iconengines/
  16. TestProject/Bin/Debug_64/iconengines/qsvgicond.dll 104.5KB
  17. TestProject/Bin/Debug_64/imageformats/
  18. TestProject/Bin/Debug_64/imageformats/qgifd.dll 100.5KB
  19. TestProject/Bin/Debug_64/imageformats/qicnsd.dll 121KB
  20. TestProject/Bin/Debug_64/imageformats/qicod.dll 100KB
  21. TestProject/Bin/Debug_64/imageformats/qjpegd.dll 514.5KB
  22. TestProject/Bin/Debug_64/imageformats/qsvgd.dll 77.5KB
  23. TestProject/Bin/Debug_64/imageformats/qtgad.dll 77.5KB
  24. TestProject/Bin/Debug_64/imageformats/qtiffd.dll 770.5KB
  25. TestProject/Bin/Debug_64/imageformats/qwbmpd.dll 74KB
  26. TestProject/Bin/Debug_64/imageformats/qwebpd.dll 1.04MB
  27. TestProject/Bin/Debug_64/libEGLd.dll 59KB
  28. TestProject/Bin/Debug_64/libGLESV2d.dll 11.9MB
  29. TestProject/Bin/Debug_64/opengl32sw.dll 19.95MB
  30. TestProject/Bin/Debug_64/platforms/
  31. TestProject/Bin/Debug_64/platforms/qwindowsd.dll 3.63MB
  32. TestProject/Bin/Debug_64/translations/
  33. TestProject/Bin/Debug_64/translations/qt_ar.qm 156.26KB
  34. TestProject/Bin/Debug_64/translations/qt_bg.qm 161.45KB
  35. TestProject/Bin/Debug_64/translations/qt_ca.qm 175.01KB
  36. TestProject/Bin/Debug_64/translations/qt_cs.qm 170.6KB
  37. TestProject/Bin/Debug_64/translations/qt_da.qm 165.68KB
  38. TestProject/Bin/Debug_64/translations/qt_de.qm 183.58KB
  39. TestProject/Bin/Debug_64/translations/qt_en.qm 23B
  40. TestProject/Bin/Debug_64/translations/qt_es.qm 161.29KB
  41. TestProject/Bin/Debug_64/translations/qt_fi.qm 171.41KB
  42. TestProject/Bin/Debug_64/translations/qt_fr.qm 162.26KB
  43. TestProject/Bin/Debug_64/translations/qt_gd.qm 185.13KB
  44. TestProject/Bin/Debug_64/translations/qt_he.qm 135.43KB
  45. TestProject/Bin/Debug_64/translations/qt_hu.qm 88.86KB
  46. TestProject/Bin/Debug_64/translations/qt_it.qm 157.35KB
  47. TestProject/Bin/Debug_64/translations/qt_ja.qm 126.86KB
  48. TestProject/Bin/Debug_64/translations/qt_ko.qm 128.18KB
  49. TestProject/Bin/Debug_64/translations/qt_lv.qm 150KB
  50. TestProject/Bin/Debug_64/translations/qt_pl.qm 159.15KB
  51. TestProject/Bin/Debug_64/translations/qt_ru.qm 154.14KB
  52. TestProject/Bin/Debug_64/translations/qt_sk.qm 122.81KB
  53. TestProject/Bin/Debug_64/translations/qt_uk.qm 154.52KB
  54. TestProject/Bin/Release_64/
  55. TestProject/Bin/Release_64/D3Dcompiler_47.dll 3.98MB
  56. TestProject/Bin/Release_64/Qt5Core.dll 5.52MB
  57. TestProject/Bin/Release_64/Qt5Gui.dll 5.77MB
  58. TestProject/Bin/Release_64/Qt5Network.dll 1.16MB
  59. TestProject/Bin/Release_64/Qt5Svg.dll 320.5KB
  60. TestProject/Bin/Release_64/Qt5Widgets.dll 5.28MB
  61. TestProject/Bin/Release_64/TidyUpQtProject.exe 78.5KB
  62. TestProject/Bin/Release_64/bearer/
  63. TestProject/Bin/Release_64/bearer/qgenericbearer.dll 47KB
  64. TestProject/Bin/Release_64/iconengines/
  65. TestProject/Bin/Release_64/iconengines/qsvgicon.dll 37KB
  66. TestProject/Bin/Release_64/imageformats/
  67. TestProject/Bin/Release_64/imageformats/qgif.dll 32KB
  68. TestProject/Bin/Release_64/imageformats/qicns.dll 39KB
  69. TestProject/Bin/Release_64/imageformats/qico.dll 34KB
  70. TestProject/Bin/Release_64/imageformats/qjpeg.dll 232KB
  71. TestProject/Bin/Release_64/imageformats/qsvg.dll 25.5KB
  72. TestProject/Bin/Release_64/imageformats/qtga.dll 25KB
  73. TestProject/Bin/Release_64/imageformats/qtiff.dll 363KB
  74. TestProject/Bin/Release_64/imageformats/qwbmp.dll 23.5KB
  75. TestProject/Bin/Release_64/imageformats/qwebp.dll 471KB
  76. TestProject/Bin/Release_64/libEGL.dll 15KB
  77. TestProject/Bin/Release_64/libGLESV2.dll 2.4MB
  78. TestProject/Bin/Release_64/opengl32sw.dll 19.95MB
  79. TestProject/Bin/Release_64/platforms/
  80. TestProject/Bin/Release_64/platforms/qwindows.dll 1.28MB
  81. TestProject/Bin/Release_64/translations/
  82. TestProject/Bin/Release_64/translations/qt_ar.qm 156.26KB
  83. TestProject/Bin/Release_64/translations/qt_bg.qm 161.45KB
  84. TestProject/Bin/Release_64/translations/qt_ca.qm 175.01KB
  85. TestProject/Bin/Release_64/translations/qt_cs.qm 170.6KB
  86. TestProject/Bin/Release_64/translations/qt_da.qm 165.68KB
  87. TestProject/Bin/Release_64/translations/qt_de.qm 183.58KB
  88. TestProject/Bin/Release_64/translations/qt_en.qm 23B
  89. TestProject/Bin/Release_64/translations/qt_es.qm 161.29KB
  90. TestProject/Bin/Release_64/translations/qt_fi.qm 171.41KB
  91. TestProject/Bin/Release_64/translations/qt_fr.qm 162.26KB
  92. TestProject/Bin/Release_64/translations/qt_gd.qm 185.13KB
  93. TestProject/Bin/Release_64/translations/qt_he.qm 135.43KB
  94. TestProject/Bin/Release_64/translations/qt_hu.qm 88.86KB
  95. TestProject/Bin/Release_64/translations/qt_it.qm 157.35KB
  96. TestProject/Bin/Release_64/translations/qt_ja.qm 126.86KB
  97. TestProject/Bin/Release_64/translations/qt_ko.qm 128.18KB
  98. TestProject/Bin/Release_64/translations/qt_lv.qm 150KB
  99. TestProject/Bin/Release_64/translations/qt_pl.qm 159.15KB
  100. TestProject/Bin/Release_64/translations/qt_ru.qm 154.14KB
  101. TestProject/Bin/Release_64/translations/qt_sk.qm 122.81KB
  102. TestProject/Bin/Release_64/translations/qt_uk.qm 154.52KB
  103. TestProject/Include/
  104. TestProject/Lib/
  105. TestProject/Source/
  106. TestProject/Source/MyCustomUdpSocket.cpp 3.09KB
  107. TestProject/Source/MyCustomUdpSocket.h 2.78KB
  108. TestProject/Source/TestProject.pro 2.63KB
  109. TestProject/Source/TestProject.pro.user 23.23KB
  110. TestProject/Source/Widget.cpp 10.72KB
  111. TestProject/Source/Widget.h 2.23KB
  112. TestProject/Source/Widget.ui 5.59KB
  113. TestProject/Source/main.cpp 175B
0评论
提交 加载更多评论
其他资源 智谱清言多轮对话生成文章工具软件介绍,支持多个API同时多线程生成
智谱清言ai生成文章软件功能介绍 1.可以设置多个api,同时每个api多线程并发批量生成文章。 2.每个api对应处理不同的TXT文件,每个txt里每行内容为一个标题。 3.可随心设置多少轮对话。但有注意事项,后边会讲。 4.自动合并多轮对话内容保存为txt文件。 5.自定义智谱清言的接口,可换接口。 6.自定义多轮生成指令。
H265原理说明帧预测
H265原理说明帧预测
H265原理说明帧预测 H265原理说明帧预测 H265原理说明帧预测
jiyuesp32dezhinengdapengjiancexitong
jiyuesp32dezhinengdapengjiancexitong
上手篇2源码上手篇2源码.zip
上手篇2源码
test111111111
test111111111
视频压缩编码原理H264
视频压缩编码原理H264
MATLAB车牌识别实现车牌定位.zip
MATLAB是一种编程语言和开发环境,可以用于图像处理和计算机视觉应用。要进行车牌检测,可以使用MATLAB提供的图像处理工具和计算机视觉工具箱。 车牌定位和检测的一般步骤如下: 1. 加载图像:使用MATLAB的图像处理工具箱中的imread函数加载车辆图像。 2. 进行图像预处理:使用一系列图像处理技术,例如灰度化、图像增强、直方图均衡化、滤波等,来提高车牌的可视性和对比度。 3. 车牌定位:使用图像处理技术,例如边缘检测、形态学操作、颜色过滤等,在图像中找到车牌的位置。 4. 车牌识别:使用计算机视觉技术,例如字符分割、特征提取、模式识别等,对车牌上的字符进行识别。 5. 显示结果:使用MATLAB的图像处理工具箱中的imwrite函数将结果保存为图像文件,并使用imshow函数显示结果。 需要注意的是,车牌检测是一个复杂的任务,可能需要使用多种技术和算法来达到较好的效果。在实际应用中,可能需要根据具体需求和场景进行调整和优化。
基于Java springboot的个人博客管理系统源码
基于Java springboot的个人博客管理系统源码