当前位置:   article > 正文

Qt之UDP通信_qt udp通信

qt udp通信

这里说明一下,UDP通信中分为三种通信分别为单播、组播和广播,下面将一一为大家介绍。

同样的我们都需要在工程文件中添加network

QT       += core gui network

进行UDP通信需要用到的头文件

#include <QUdpSocket>

这里我们把UDP通信分为两个部分写,一个是发送端,另一个是接收端,而发送端中又分为单播、组播和广播三种形式,下面我们先来看看写发送端的代码程序的步骤:

发送端Udpsend的代码:

1、单播

(1)创建套接字

  1. QUdpSocket mSocket;
  2. mSocket = new QUdpSocket();

(2)发送数据到指定的地址和端口号

  1. mSocket->writeDatagram(ui->textEdit->toPlainText().toUtf8(),QHostAddress("192.168.137.1"),6677);
  2. 参数:ui->textEdit->toPlainText().toUtf8 要发送的消息
  3. QHostAddress("192.168.137.1") 接收端的ip地址
  4. 6677 端口号,要和接收端的一致

2、组播,组播和单播的步骤是一样的,只有ip地址处有区别

  1. 组播ip地址范围:224.0.0.0-239.255.255.255
  2. 例子:mSocket->writeDatagram(ui->textEdit->toPlainText().toUtf8(),QHostAddress("224.0.0.100"),6677);

3、广播,广播也只有ip地址和单播有区别

  1. 广播地址ip:QHostAddress::Broadcast
  2. 例子:mSocket->writeDatagram(ui->textEdit->toPlainText().toUtf8(),QHostAddress::Broadcast,6677);

好了,单播、组播和广播的区别应该都了解了,那么我们就来看发送端(udpsend.cpp)的具体代码:

  1. #include "udpsend.h"
  2. #include "ui_udpsend.h"
  3. UdpSend:: UdpSend(QWidget *parent) :
  4. QMainWindow(parent),
  5. ui(new Ui:: UdpSend)
  6. {
  7. ui->setupUi(this);
  8. //初始化创建QUdpSocket对象
  9. mSocket = new QUdpSocket();
  10. }
  11. UdpSend::~ UdpSend()
  12. {
  13. delete ui;
  14. }
  15. void UdpSend::on_sendBt_clicked()
  16. {
  17. //单播
  18. // qint64 len = mSocket->writeDatagram(ui->textEdit->toPlainText().toUtf8(),QHostAddress("192.168.137.1"),6677);
  19. //组播ip地址范围:224.0.0.0-239.255.255.255
  20. //qint64 len = mSocket->writeDatagram(ui->textEdit->toPlainText().toUtf8(),QHostAddress("224.0.0.100"),6677);
  21. //广播
  22. qint64 len = mSocket->writeDatagram(ui->textEdit->toPlainText().toUtf8(),QHostAddress::Broadcast,6677);
  23. }

发送端的界面文件我做的很简单,我只做了发送消息框:

看完发送端的代码,我们继续来看接收端的代码(Udprecv)

接收端不管是单播、或者组播还是广播代码都是一样的,下面是写接收端代码的步骤:

1、创建套接字

  1. QUdpSocket mSocket;
  2. mSocket = new QUdpSocket();

2、绑定地址和端口号

  1. mSocket->bind(QHostAddress::AnyIPv4,6677);
  2. 参数:AnyIPv4 IPv4
  3. 6677 端口号,要和发送端的一致

3、等待数据的到来,利用readyRread()

connect(mSocket,SIGNAL(readyRead()),this,SLOT(read_data()));

4、读数据

  1. readDatagram(char * data, qint64 maxSize, QHostAddress * address = 0, quint16 * port = 0)
  2. 参数:
  3. data:数据
  4. maxSize:数据的大小
  5. address:QHostAddress类型的地址
  6. port:端口号
  7. 例子:
  8. void UdpRecv::read_data()
  9. {
  10. QByteArray array;
  11. QHostAddress address;
  12. quint16 port;
  13. array.resize(mSocket->bytesAvailable());//根据可读数据来设置空间大小
  14. mSocket->readDatagram(array.data(),array.size(),&address,&port); //读取数据
  15. ui->listWidget->addItem(array);//显示数据
  16. //发送反馈数据
  17. }

如果是组播的话还涉及到加入组播和退出组播

  1. 加入到组播组 joinMulticastGroup
  2. 例子:mSocket->joinMulticastGroup(QHostAddress("224.0.0.100"));
  3. 退出组播组 leaveMulticastGroup
  4. 例子: mSocket->leaveMulticastGroup(QHostAddress("224.0.0.100"));

来看看接收端(Udprecv.cpp)具体实现的代码

  1. #include "udprecv.h"
  2. #include "ui_udprecv.h"
  3. UdpRecv::UdpRecv(QWidget *parent) :
  4. QMainWindow(parent),
  5. ui(new Ui::UdpRecv)
  6. {
  7. ui->setupUi(this);
  8. //创建对象 初始化
  9. mSocket = new QUdpSocket();
  10. //绑定
  11. mSocket->bind(QHostAddress::AnyIPv4,6677);
  12. //关联读数据信号readyread
  13. connect(mSocket,SIGNAL(readyRead()),this,SLOT(read_data()));
  14. }
  15. UdpRecv::~UdpRecv()
  16. {
  17. delete ui;
  18. }
  19. void UdpRecv::read_data()
  20. {
  21. QByteArray array;
  22. QHostAddress address;
  23. quint16 port;
  24. array.resize(mSocket->bytesAvailable());//根据可读数据来设置空间大小
  25. mSocket->readDatagram(array.data(),array.size(),&address,&port); //读取数据
  26. ui->listWidget->addItem(array);//显示数据
  27. //发送反馈数据
  28. }
  29. void UdpRecv::on_checkBox_clicked(bool checked)
  30. {
  31. if(checked)
  32. {
  33. //加入组播
  34. mSocket->joinMulticastGroup(QHostAddress("224.0.0.100"));
  35. }
  36. else
  37. {
  38. //退出组播
  39. mSocket->leaveMulticastGroup(QHostAddress("224.0.0.100"));
  40. }
  41. }

接收端的界面文件我只加了显示接收到的信息和选择是否加入组播的选择按钮

这是发送端和接收分开来写的,此外我也实现了一下发送端和接收端写到同一个文件中

头文件qudpapp.h中的代码

  1. 1 #ifndef QUDPAPP_H
  2. 2 #define QUDPAPP_H
  3. 3
  4. 4 #include <QWidget>
  5. 5 #include <QUdpSocket>
  6. 6 namespace Ui {
  7. 7 class QUdpApp;
  8. 8 }
  9. 9
  10. 10 class QUdpApp : public QWidget
  11. 11 {
  12. 12 Q_OBJECT
  13. 13
  14. 14 public:
  15. 15 explicit QUdpApp(QWidget *parent = 0);
  16. 16 ~QUdpApp();
  17. 17
  18. 18 private slots:
  19. 19 void on_sendSigRb_clicked(); //单播旋转轴
  20. 20 void on_sendMulRb_clicked(); //组播选择
  21. 21 void on_sendBroadRb_clicked(); //广播选择
  22. 22 void on_sendBt_clicked(); //发送按钮
  23. 23
  24. 24 //===========================================
  25. 25 void on_recvCb_clicked(bool checked); //选择接收
  26. 26 void on_recvJoinMulBt_clicked(); //加入组播
  27. 27 void on_recvLeaveMulBt_clicked(); //退出组播
  28. 28
  29. 29 void on_sendMesEdit_cursorPositionChanged();//检测消息框是否有数据
  30. 30 void read_data();
  31. 31
  32. 32 private:
  33. 33 Ui::QUdpApp *ui;
  34. 34 QUdpSocket *mSocket;
  35. 35 QHostAddress sendaddrees;
  36. 36 QString sendPort;
  37. 37
  38. 38 };
  39. 39
  40. 40 #endif // QUDPAPP_H

源文件qudpapp.cpp中的代码

  1. 1 #include "qudpapp.h"
  2. 2 #include "ui_qudpapp.h"
  3. 3 #include <QMessageBox>
  4. 4 QUdpApp::QUdpApp(QWidget *parent) :
  5. 5 QWidget(parent),
  6. 6 ui(new Ui::QUdpApp)
  7. 7 {
  8. 8 ui->setupUi(this);
  9. 9 mSocket = new QUdpSocket();//创建套接字
  10. 10 ui->sendBt->setEnabled(false);
  11. 11 }
  12. 12
  13. 13 QUdpApp::~QUdpApp()
  14. 14 {
  15. 15 delete ui;
  16. 16 }
  17. 17
  18. 18
  19. 19 //==========================发送端====================
  20. 20 //单播选择
  21. 21 void QUdpApp::on_sendSigRb_clicked()
  22. 22 {
  23. 23 if(ui->sendPortEdit->text().isEmpty() || ui->sendSigAddrEdit->text().isEmpty())
  24. 24 {
  25. 25 QMessageBox::warning(this,"提示","请输入单播ip和端口号");
  26. 26 //ui->sendSigRb->setChecked(false);
  27. 27 return;
  28. 28 }
  29. 29 sendaddrees.setAddress( ui->sendSigAddrEdit->text());
  30. 30 sendPort = ui->sendPortEdit->text();
  31. 31
  32. 32 }
  33. 33
  34. 34 //组播选择
  35. 35 void QUdpApp::on_sendMulRb_clicked()
  36. 36 {
  37. 37 if(ui->sendPortEdit->text().isEmpty() || ui->sendMulAddrEdit->text().isEmpty())
  38. 38 {
  39. 39 QMessageBox::warning(this,"提示","请输入组播ip和端口号");
  40. 40 //ui->sendSigRb->setChecked(false);
  41. 41 return;
  42. 42 }
  43. 43 sendaddrees.setAddress( ui->sendMulAddrEdit->text());
  44. 44 sendPort = ui->sendPortEdit->text();
  45. 45
  46. 46 }
  47. 47
  48. 48 //广播选择
  49. 49 void QUdpApp::on_sendBroadRb_clicked()
  50. 50 {
  51. 51 if(ui->sendPortEdit->text().isEmpty() || ui->sendBroadAddrEdit->text().isEmpty())
  52. 52 {
  53. 53 QMessageBox::warning(this,"提示","请输入广播ip和端口号");
  54. 54 //ui->sendSigRb->setChecked(false);
  55. 55 return;
  56. 56 }
  57. 57 sendaddrees.setAddress( ui->sendBroadAddrEdit->text());
  58. 58 sendPort = ui->sendPortEdit->text();
  59. 59
  60. 60 }
  61. 61
  62. 62 //发送按钮
  63. 63 void QUdpApp::on_sendBt_clicked()
  64. 64 {
  65. 65 mSocket->writeDatagram(ui->sendMesEdit->toPlainText().toUtf8(),sendaddrees,sendPort.toInt());
  66. 66
  67. 67 }
  68. 68
  69. 69 //检测发送消息对话框中是否有消息
  70. 70 void QUdpApp::on_sendMesEdit_cursorPositionChanged()
  71. 71 {
  72. 72 if(ui->sendMesEdit->toPlainText().isEmpty())
  73. 73 {
  74. 74 ui->sendBt->setEnabled(false);
  75. 75 }
  76. 76 else
  77. 77 {
  78. 78 ui->sendBt->setEnabled(true);
  79. 79 }
  80. 80
  81. 81 }
  82. 82
  83. 83 //==========================发送端====================
  84. 84
  85. 85
  86. 86 //==========================接收端=====================
  87. 87
  88. 88 //选择接收
  89. 89 void QUdpApp::on_recvCb_clicked(bool checked)
  90. 90 {
  91. 91 if(ui->recvPortEdit->text().isEmpty())
  92. 92 {
  93. 93 QMessageBox::warning(this,"提示","请输入端口号");
  94. 94 ui->recvCb->setChecked(false);
  95. 95 return;
  96. 96 }
  97. 97 if(checked)
  98. 98 {
  99. 99 mSocket->bind(QHostAddress::AnyIPv4,ui->recvPortEdit->text().toInt());
  100. 100 connect(mSocket,SIGNAL(readyRead()),this,SLOT(read_data()));
  101. 101 ui->recvPortEdit->setEnabled(false);
  102. 102 }
  103. 103 else
  104. 104 {
  105. 105 mSocket->close();
  106. 106 ui->recvPortEdit->setEnabled(true);
  107. 107 }
  108. 108 }
  109. 109
  110. 110 //加入组播
  111. 111 void QUdpApp::on_recvJoinMulBt_clicked()
  112. 112 {
  113. 113 if(ui->recvMulAddrEdit->text().isEmpty())
  114. 114 {
  115. 115 QMessageBox::warning(this,"提示","请输入组播ip");
  116. 116 return;
  117. 117 }
  118. 118 if(mSocket->joinMulticastGroup(QHostAddress(ui->recvMulAddrEdit->text()))) //加入组播
  119. 119 {
  120. 120 ui->recvMulAddr->addItem(ui->recvMulAddrEdit->text());
  121. 121 }
  122. 122 else
  123. 123 {
  124. 124 QMessageBox::warning(this,"提示","加入组播失败,请修改ip后继续加入");
  125. 125 //return;
  126. 126 }
  127. 127
  128. 128 }
  129. 129
  130. 130 //退出组播
  131. 131 void QUdpApp::on_recvLeaveMulBt_clicked()
  132. 132 {
  133. 133 mSocket->leaveMulticastGroup(QHostAddress(ui->recvMulAddr->currentIndex()));//退出组播地址列表当前的组播
  134. 134 ui->recvMulAddr->removeItem(ui->recvMulAddr->currentIndex()); //删除组播地址列表中当前的组播地址
  135. 135 }
  136. 136
  137. 137 void QUdpApp::read_data()
  138. 138 {
  139. 139 QByteArray array;
  140. 140 array.resize(mSocket->bytesAvailable()); //将接收数据的array设置成为要接收数据的大小
  141. 141 QHostAddress recvaddress;
  142. 142 quint16 port;
  143. 143 mSocket->readDatagram(array.data(),array.size(),&recvaddress,&port); //读取数据
  144. 144 ui->recvList->addItem(array);
  145. 145
  146. 146 }
  147. 147
  148. 148 //==========================接收端=====================

界面文件qudpapp.ui

  1. 1 <?xml version="1.0" encoding="UTF-8"?>
  2. 2 <ui version="4.0">
  3. 3 <class>QUdpApp</class>
  4. 4 <widget class="QWidget" name="QUdpApp">
  5. 5 <property name="geometry">
  6. 6 <rect>
  7. 7 <x>0</x>
  8. 8 <y>0</y>
  9. 9 <width>637</width>
  10. 10 <height>561</height>
  11. 11 </rect>
  12. 12 </property>
  13. 13 <property name="sizePolicy">
  14. 14 <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
  15. 15 <horstretch>0</horstretch>
  16. 16 <verstretch>0</verstretch>
  17. 17 </sizepolicy>
  18. 18 </property>
  19. 19 <property name="windowTitle">
  20. 20 <string>QUdpApp</string>
  21. 21 </property>
  22. 22 <widget class="QWidget" name="layoutWidget">
  23. 23 <property name="geometry">
  24. 24 <rect>
  25. 25 <x>9</x>
  26. 26 <y>9</y>
  27. 27 <width>394</width>
  28. 28 <height>463</height>
  29. 29 </rect>
  30. 30 </property>
  31. 31 <layout class="QVBoxLayout" name="verticalLayout_6">
  32. 32 <item>
  33. 33 <layout class="QHBoxLayout" name="horizontalLayout_9">
  34. 34 <item>
  35. 35 <widget class="QGroupBox" name="groupBox">
  36. 36 <property name="sizePolicy">
  37. 37 <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
  38. 38 <horstretch>0</horstretch>
  39. 39 <verstretch>0</verstretch>
  40. 40 </sizepolicy>
  41. 41 </property>
  42. 42 <property name="title">
  43. 43 <string>发送端</string>
  44. 44 </property>
  45. 45 <layout class="QVBoxLayout" name="verticalLayout_3">
  46. 46 <property name="spacing">
  47. 47 <number>0</number>
  48. 48 </property>
  49. 49 <property name="leftMargin">
  50. 50 <number>0</number>
  51. 51 </property>
  52. 52 <property name="topMargin">
  53. 53 <number>0</number>
  54. 54 </property>
  55. 55 <property name="rightMargin">
  56. 56 <number>0</number>
  57. 57 </property>
  58. 58 <property name="bottomMargin">
  59. 59 <number>0</number>
  60. 60 </property>
  61. 61 <item>
  62. 62 <layout class="QVBoxLayout" name="verticalLayout_2">
  63. 63 <item>
  64. 64 <layout class="QHBoxLayout" name="horizontalLayout">
  65. 65 <property name="spacing">
  66. 66 <number>0</number>
  67. 67 </property>
  68. 68 <item>
  69. 69 <widget class="QLabel" name="label">
  70. 70 <property name="text">
  71. 71 <string>端 口 号</string>
  72. 72 </property>
  73. 73 </widget>
  74. 74 </item>
  75. 75 <item>
  76. 76 <widget class="QLineEdit" name="sendPortEdit">
  77. 77 <property name="sizePolicy">
  78. 78 <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
  79. 79 <horstretch>0</horstretch>
  80. 80 <verstretch>0</verstretch>
  81. 81 </sizepolicy>
  82. 82 </property>
  83. 83 <property name="placeholderText">
  84. 84 <string>请输入端口号</string>
  85. 85 </property>
  86. 86 </widget>
  87. 87 </item>
  88. 88 </layout>
  89. 89 </item>
  90. 90 <item>
  91. 91 <layout class="QHBoxLayout" name="horizontalLayout_2">
  92. 92 <property name="spacing">
  93. 93 <number>0</number>
  94. 94 </property>
  95. 95 <item>
  96. 96 <widget class="QRadioButton" name="sendSigRb">
  97. 97 <property name="text">
  98. 98 <string>单播</string>
  99. 99 </property>
  100. 100 </widget>
  101. 101 </item>
  102. 102 <item>
  103. 103 <widget class="QLineEdit" name="sendSigAddrEdit">
  104. 104 <property name="sizePolicy">
  105. 105 <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
  106. 106 <horstretch>0</horstretch>
  107. 107 <verstretch>0</verstretch>
  108. 108 </sizepolicy>
  109. 109 </property>
  110. 110 <property name="placeholderText">
  111. 111 <string>请输入接收方地址</string>
  112. 112 </property>
  113. 113 </widget>
  114. 114 </item>
  115. 115 </layout>
  116. 116 </item>
  117. 117 <item>
  118. 118 <layout class="QHBoxLayout" name="horizontalLayout_3">
  119. 119 <property name="spacing">
  120. 120 <number>0</number>
  121. 121 </property>
  122. 122 <item>
  123. 123 <widget class="QRadioButton" name="sendMulRb">
  124. 124 <property name="text">
  125. 125 <string>组播</string>
  126. 126 </property>
  127. 127 </widget>
  128. 128 </item>
  129. 129 <item>
  130. 130 <widget class="QLineEdit" name="sendMulAddrEdit">
  131. 131 <property name="sizePolicy">
  132. 132 <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
  133. 133 <horstretch>0</horstretch>
  134. 134 <verstretch>0</verstretch>
  135. 135 </sizepolicy>
  136. 136 </property>
  137. 137 <property name="placeholderText">
  138. 138 <string>请输入组播地址</string>
  139. 139 </property>
  140. 140 </widget>
  141. 141 </item>
  142. 142 </layout>
  143. 143 </item>
  144. 144 <item>
  145. 145 <layout class="QHBoxLayout" name="horizontalLayout_4">
  146. 146 <property name="spacing">
  147. 147 <number>0</number>
  148. 148 </property>
  149. 149 <item>
  150. 150 <widget class="QRadioButton" name="sendBroadRb">
  151. 151 <property name="text">
  152. 152 <string>广播</string>
  153. 153 </property>
  154. 154 </widget>
  155. 155 </item>
  156. 156 <item>
  157. 157 <widget class="QLineEdit" name="sendBroadAddrEdit">
  158. 158 <property name="sizePolicy">
  159. 159 <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
  160. 160 <horstretch>0</horstretch>
  161. 161 <verstretch>0</verstretch>
  162. 162 </sizepolicy>
  163. 163 </property>
  164. 164 <property name="placeholderText">
  165. 165 <string>请输入广播地址</string>
  166. 166 </property>
  167. 167 </widget>
  168. 168 </item>
  169. 169 </layout>
  170. 170 </item>
  171. 171 </layout>
  172. 172 </item>
  173. 173 </layout>
  174. 174 </widget>
  175. 175 </item>
  176. 176 <item>
  177. 177 <widget class="QGroupBox" name="groupBox_2">
  178. 178 <property name="sizePolicy">
  179. 179 <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
  180. 180 <horstretch>0</horstretch>
  181. 181 <verstretch>0</verstretch>
  182. 182 </sizepolicy>
  183. 183 </property>
  184. 184 <property name="title">
  185. 185 <string>接收端</string>
  186. 186 </property>
  187. 187 <layout class="QVBoxLayout" name="verticalLayout_4">
  188. 188 <item>
  189. 189 <layout class="QVBoxLayout" name="verticalLayout">
  190. 190 <item>
  191. 191 <layout class="QHBoxLayout" name="horizontalLayout_7">
  192. 192 <item>
  193. 193 <widget class="QCheckBox" name="recvCb">
  194. 194 <property name="text">
  195. 195 <string>接收</string>
  196. 196 </property>
  197. 197 </widget>
  198. 198 </item>
  199. 199 <item>
  200. 200 <widget class="QLineEdit" name="recvPortEdit">
  201. 201 <property name="placeholderText">
  202. 202 <string>请输入端口号</string>
  203. 203 </property>
  204. 204 </widget>
  205. 205 </item>
  206. 206 </layout>
  207. 207 </item>
  208. 208 <item>
  209. 209 <layout class="QHBoxLayout" name="horizontalLayout_5">
  210. 210 <property name="spacing">
  211. 211 <number>0</number>
  212. 212 </property>
  213. 213 <item>
  214. 214 <widget class="QLineEdit" name="recvMulAddrEdit">
  215. 215 <property name="placeholderText">
  216. 216 <string>输入要加入的组播地址</string>
  217. 217 </property>
  218. 218 </widget>
  219. 219 </item>
  220. 220 <item>
  221. 221 <widget class="QPushButton" name="recvJoinMulBt">
  222. 222 <property name="maximumSize">
  223. 223 <size>
  224. 224 <width>40</width>
  225. 225 <height>16777215</height>
  226. 226 </size>
  227. 227 </property>
  228. 228 <property name="text">
  229. 229 <string>加入</string>
  230. 230 </property>
  231. 231 </widget>
  232. 232 </item>
  233. 233 </layout>
  234. 234 </item>
  235. 235 <item>
  236. 236 <layout class="QHBoxLayout" name="horizontalLayout_6">
  237. 237 <item>
  238. 238 <widget class="QComboBox" name="recvMulAddr"/>
  239. 239 </item>
  240. 240 <item>
  241. 241 <widget class="QPushButton" name="recvLeaveMulBt">
  242. 242 <property name="maximumSize">
  243. 243 <size>
  244. 244 <width>40</width>
  245. 245 <height>16777215</height>
  246. 246 </size>
  247. 247 </property>
  248. 248 <property name="text">
  249. 249 <string>退出</string>
  250. 250 </property>
  251. 251 </widget>
  252. 252 </item>
  253. 253 </layout>
  254. 254 </item>
  255. 255 </layout>
  256. 256 </item>
  257. 257 </layout>
  258. 258 </widget>
  259. 259 </item>
  260. 260 </layout>
  261. 261 </item>
  262. 262 <item>
  263. 263 <layout class="QVBoxLayout" name="verticalLayout_5">
  264. 264 <item>
  265. 265 <widget class="QListWidget" name="recvList"/>
  266. 266 </item>
  267. 267 <item>
  268. 268 <widget class="QTextEdit" name="sendMesEdit">
  269. 269 <property name="maximumSize">
  270. 270 <size>
  271. 271 <width>16777215</width>
  272. 272 <height>100</height>
  273. 273 </size>
  274. 274 </property>
  275. 275 </widget>
  276. 276 </item>
  277. 277 </layout>
  278. 278 </item>
  279. 279 <item>
  280. 280 <layout class="QHBoxLayout" name="horizontalLayout_8">
  281. 281 <item>
  282. 282 <widget class="QPushButton" name="clearRecvListBt">
  283. 283 <property name="text">
  284. 284 <string>清除接收区</string>
  285. 285 </property>
  286. 286 </widget>
  287. 287 </item>
  288. 288 <item>
  289. 289 <widget class="QPushButton" name="clearsendEditBt">
  290. 290 <property name="text">
  291. 291 <string>清除发送区</string>
  292. 292 </property>
  293. 293 </widget>
  294. 294 </item>
  295. 295 <item>
  296. 296 <spacer name="horizontalSpacer_2">
  297. 297 <property name="orientation">
  298. 298 <enum>Qt::Horizontal</enum>
  299. 299 </property>
  300. 300 <property name="sizeHint" stdset="0">
  301. 301 <size>
  302. 302 <width>40</width>
  303. 303 <height>20</height>
  304. 304 </size>
  305. 305 </property>
  306. 306 </spacer>
  307. 307 </item>
  308. 308 <item>
  309. 309 <widget class="QPushButton" name="sendBt">
  310. 310 <property name="text">
  311. 311 <string>发送</string>
  312. 312 </property>
  313. 313 </widget>
  314. 314 </item>
  315. 315 </layout>
  316. 316 </item>
  317. 317 </layout>
  318. 318 </widget>
  319. 319 </widget>
  320. 320 <layoutdefault spacing="6" margin="11"/>
  321. 321 <resources/>
  322. 322 <connections>
  323. 323 <connection>
  324. 324 <sender>clearRecvListBt</sender>
  325. 325 <signal>clicked()</signal>
  326. 326 <receiver>recvList</receiver>
  327. 327 <slot>clear()</slot>
  328. 328 <hints>
  329. 329 <hint type="sourcelabel">
  330. 330 <x>47</x>
  331. 331 <y>448</y>
  332. 332 </hint>
  333. 333 <hint type="destinationlabel">
  334. 334 <x>70</x>
  335. 335 <y>227</y>
  336. 336 </hint>
  337. 337 </hints>
  338. 338 </connection>
  339. 339 <connection>
  340. 340 <sender>clearsendEditBt</sender>
  341. 341 <signal>clicked()</signal>
  342. 342 <receiver>sendMesEdit</receiver>
  343. 343 <slot>clear()</slot>
  344. 344 <hints>
  345. 345 <hint type="sourcelabel">
  346. 346 <x>134</x>
  347. 347 <y>455</y>
  348. 348 </hint>
  349. 349 <hint type="destinationlabel">
  350. 350 <x>145</x>
  351. 351 <y>410</y>
  352. 352 </hint>
  353. 353 </hints>
  354. 354 </connection>
  355. 355 </connections>
  356. 356 </ui>

界面文件图示

【领QT开发教程学习资料,进Qt开发交流君羊:546183882 莬废领取,先码住不迷路~】

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/305235
推荐阅读
相关标签
  

闽ICP备14008679号