feat: TcpClient 客户端写槽函数
This commit is contained in:
parent
9a6a17caff
commit
466761915f
@ -12,3 +12,40 @@ ExTcpClient::~ExTcpClient()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString ExTcpClient::getLocalIp()
|
||||
{
|
||||
QString hostName = QHostInfo::localHostName();
|
||||
QHostInfo hostInfo = QHostInfo::fromName(hostName);
|
||||
ui->plainTextEdit->appendPlainText("本机名称:" + hostName);
|
||||
QString localIp;
|
||||
|
||||
foreach (QHostAddress addr, hostInfo.addresses()) {
|
||||
if (QAbstractSocket::IPv4Protocol == addr.toString()) {
|
||||
localIp = addr.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return localIp;
|
||||
}
|
||||
|
||||
void ExTcpClient::on_actConnect_triggered()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ExTcpClient::on_actDisconnect_triggered()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ExTcpClient::on_actClear_triggered()
|
||||
{
|
||||
ui->plainTextEdit->clear();
|
||||
}
|
||||
|
||||
void ExTcpClient::on_actQuit_triggered()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
@ -2,6 +2,9 @@
|
||||
#define EXTCPCLIENT_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QLabel>
|
||||
#include <QTcpSocket>
|
||||
#include <QHostInfo>
|
||||
|
||||
namespace Ui {
|
||||
class ExTcpClient;
|
||||
@ -15,8 +18,22 @@ public:
|
||||
explicit ExTcpClient(QWidget *parent = nullptr);
|
||||
~ExTcpClient();
|
||||
|
||||
private:
|
||||
QString getLocalIp(); //获取本本机 IP
|
||||
|
||||
|
||||
private slots:
|
||||
//UI 定义的槽函数
|
||||
void on_actConnect_triggered(); //请求连接到服务器
|
||||
void on_actDisconnect_triggered(); //断开与服务器的连接
|
||||
void on_actClear_triggered(); //清除内容
|
||||
void on_actQuit_triggered(); //退出程序
|
||||
|
||||
private:
|
||||
Ui::ExTcpClient *ui;
|
||||
|
||||
QLabel* m_labSocket;
|
||||
QTcpSocket* m_tcpSocket;
|
||||
};
|
||||
|
||||
#endif // EXTCPCLIENT_H
|
||||
|
@ -4,7 +4,7 @@
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
QT += core gui network
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
@ -51,8 +51,7 @@ qnx: target.path = /tmp/$${TARGET}/bin
|
||||
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||
!isEmpty(target.path): INSTALLS += target
|
||||
|
||||
DISTFILES += \
|
||||
images/Image2.jpg \
|
||||
images/Image1.png \
|
||||
images/Image4.png \
|
||||
images/Image5.png
|
||||
DISTFILES +=
|
||||
|
||||
RESOURCES += \
|
||||
resource.qrc
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>561</width>
|
||||
<height>353</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -81,7 +81,7 @@
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnSenf">
|
||||
<widget class="QPushButton" name="btnSend">
|
||||
<property name="text">
|
||||
<string>发送</string>
|
||||
</property>
|
||||
@ -96,7 +96,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<width>561</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -108,9 +108,63 @@
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actConnect"/>
|
||||
<addaction name="actDisconnect"/>
|
||||
<addaction name="actClear"/>
|
||||
<addaction name="actQuit"/>
|
||||
</widget>
|
||||
<action name="actConnect">
|
||||
<property name="icon">
|
||||
<iconset resource="resource.qrc">
|
||||
<normaloff>:/images/Image4.png</normaloff>:/images/Image4.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>请求连接</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>请求连接到服务器</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actDisconnect">
|
||||
<property name="icon">
|
||||
<iconset resource="resource.qrc">
|
||||
<normaloff>:/images/Image5.png</normaloff>:/images/Image5.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>断开连接</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>断开与服务器的连接</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actClear">
|
||||
<property name="icon">
|
||||
<iconset resource="resource.qrc">
|
||||
<normaloff>:/images/Image1.png</normaloff>:/images/Image1.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>清空</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>清空编辑框文本</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actQuit">
|
||||
<property name="icon">
|
||||
<iconset resource="resource.qrc">
|
||||
<normaloff>:/images/Image2.jpg</normaloff>:/images/Image2.jpg</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>退出</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>退出程序</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="resource.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
8
QtTcpEx/ExTcpClient/resource.qrc
Normal file
8
QtTcpEx/ExTcpClient/resource.qrc
Normal file
@ -0,0 +1,8 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/Image5.png</file>
|
||||
<file>images/Image4.png</file>
|
||||
<file>images/Image2.jpg</file>
|
||||
<file>images/Image1.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
Loading…
Reference in New Issue
Block a user