Socket网络编程

 Step1:首先完成整个界面的设计

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>421</width>
    <height>533</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralWidget">
   <widget class="QLineEdit" name="IP_Address">
    <property name="geometry">
     <rect>
      <x>30</x>
      <y>140</y>
      <width>113</width>
      <height>27</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="label_4">
    <property name="geometry">
     <rect>
      <x>20</x>
      <y>100</y>
      <width>171</width>
      <height>21</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>10</pointsize>
      <italic>true</italic>
      <underline>false</underline>
      <strikeout>false</strikeout>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>BlankCursor</cursorShape>
    </property>
    <property name="text">
     <string>Designed by : mm1994uestc</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
   <widget class="QLabel" name="label_6">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>-10</y>
      <width>321</width>
      <height>51</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>28</pointsize>
      <italic>true</italic>
      <underline>false</underline>
      <strikeout>false</strikeout>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>BlankCursor</cursorShape>
    </property>
    <property name="text">
     <string>Qt interface Demo!</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
   <widget class="QLabel" name="label_5">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>40</y>
      <width>171</width>
      <height>51</height>
     </rect>
    </property>
    <property name="font">
     <font>
      <pointsize>16</pointsize>
      <italic>true</italic>
      <underline>false</underline>
      <strikeout>false</strikeout>
     </font>
    </property>
    <property name="cursor">
     <cursorShape>BlankCursor</cursorShape>
    </property>
    <property name="text">
     <string>Socket Control</string>
    </property>
    <property name="alignment">
     <set>Qt::AlignCenter</set>
    </property>
   </widget>
   <widget class="QLineEdit" name="Client_Port">
    <property name="geometry">
     <rect>
      <x>200</x>
      <y>140</y>
      <width>51</width>
      <height>27</height>
     </rect>
    </property>
   </widget>
   <widget class="QPushButton" name="Client_Button">
    <property name="geometry">
     <rect>
      <x>260</x>
      <y>140</y>
      <width>151</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>TCP-Client-Connect</string>
    </property>
   </widget>
   <widget class="QLabel" name="label">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>130</y>
      <width>21</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string>IP:</string>
    </property>
   </widget>
   <widget class="QLabel" name="label_2">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>130</y>
      <width>51</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string>PORT:</string>
    </property>
   </widget>
   <widget class="QLineEdit" name="Server_Port">
    <property name="geometry">
     <rect>
      <x>60</x>
      <y>320</y>
      <width>51</width>
      <height>27</height>
     </rect>
    </property>
   </widget>
   <widget class="QLabel" name="label_3">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>310</y>
      <width>51</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string>PORT:</string>
    </property>
   </widget>
   <widget class="QPushButton" name="Server_Button">
    <property name="geometry">
     <rect>
      <x>120</x>
      <y>320</y>
      <width>161</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>TCP-Server-Monitor</string>
    </property>
   </widget>
   <widget class="QLabel" name="label_7">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>170</y>
      <width>151</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string>Data Ricieve Frame:</string>
    </property>
   </widget>
   <widget class="QLabel" name="label_8">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>170</y>
      <width>151</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string>Data Send Frame:</string>
    </property>
   </widget>
   <widget class="QLabel" name="label_9">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>350</y>
      <width>151</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string>Data Ricieve Frame:</string>
    </property>
   </widget>
   <widget class="QLabel" name="label_10">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>350</y>
      <width>151</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string>Data Send Frame:</string>
    </property>
   </widget>
   <widget class="QLabel" name="Corver">
    <property name="geometry">
     <rect>
      <x>220</x>
      <y>40</y>
      <width>171</width>
      <height>91</height>
     </rect>
    </property>
    <property name="text">
     <string>                     Corver</string>
    </property>
   </widget>
   <widget class="QPushButton" name="pushButton">
    <property name="geometry">
     <rect>
      <x>350</x>
      <y>180</y>
      <width>51</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>Send</string>
    </property>
   </widget>
   <widget class="QPushButton" name="ServerSend">
    <property name="geometry">
     <rect>
      <x>350</x>
      <y>360</y>
      <width>51</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>Send</string>
    </property>
   </widget>
   <widget class="QPlainTextEdit" name="Client_Recieve">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>210</y>
      <width>171</width>
      <height>101</height>
     </rect>
    </property>
   </widget>
   <widget class="QPlainTextEdit" name="Client_Send">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>210</y>
      <width>171</width>
      <height>101</height>
     </rect>
    </property>
   </widget>
   <widget class="QPlainTextEdit" name="Server_Recieve">
    <property name="geometry">
     <rect>
      <x>10</x>
      <y>390</y>
      <width>171</width>
      <height>101</height>
     </rect>
    </property>
   </widget>
   <widget class="QPlainTextEdit" name="Server_Send">
    <property name="geometry">
     <rect>
      <x>230</x>
      <y>390</y>
      <width>171</width>
      <height>101</height>
     </rect>
    </property>
   </widget>
   <widget class="QPushButton" name="Client_Clear">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>180</y>
      <width>51</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>Clear</string>
    </property>
   </widget>
   <widget class="QPushButton" name="Server_Clear">
    <property name="geometry">
     <rect>
      <x>150</x>
      <y>360</y>
      <width>51</width>
      <height>27</height>
     </rect>
    </property>
    <property name="text">
     <string>Clear</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>421</width>
     <height>25</height>
    </rect>
   </property>
  </widget>
  <widget class="QToolBar" name="mainToolBar">
   <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
   </attribute>
   <attribute name="toolBarBreak">
    <bool>false</bool>
   </attribute>
  </widget>
  <widget class="QStatusBar" name="statusBar"/>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections/>
</ui>
View Code

相关文章: