feat: TcpClient 客户端写槽函数
This commit is contained in:
parent
9a6a17caff
commit
466761915f
@ -12,3 +12,40 @@ ExTcpClient::~ExTcpClient()
|
|||||||
{
|
{
|
||||||
delete ui;
|
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
|
#define EXTCPCLIENT_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QHostInfo>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ExTcpClient;
|
class ExTcpClient;
|
||||||
@ -15,8 +18,22 @@ public:
|
|||||||
explicit ExTcpClient(QWidget *parent = nullptr);
|
explicit ExTcpClient(QWidget *parent = nullptr);
|
||||||
~ExTcpClient();
|
~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:
|
private:
|
||||||
Ui::ExTcpClient *ui;
|
Ui::ExTcpClient *ui;
|
||||||
|
|
||||||
|
QLabel* m_labSocket;
|
||||||
|
QTcpSocket* m_tcpSocket;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EXTCPCLIENT_H
|
#endif // EXTCPCLIENT_H
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
QT += core gui
|
QT += core gui network
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
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
|
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||||
!isEmpty(target.path): INSTALLS += target
|
!isEmpty(target.path): INSTALLS += target
|
||||||
|
|
||||||
DISTFILES += \
|
DISTFILES +=
|
||||||
images/Image2.jpg \
|
|
||||||
images/Image1.png \
|
RESOURCES += \
|
||||||
images/Image4.png \
|
resource.qrc
|
||||||
images/Image5.png
|
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>561</width>
|
||||||
<height>300</height>
|
<height>353</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -81,7 +81,7 @@
|
|||||||
<widget class="QLineEdit" name="lineEdit"/>
|
<widget class="QLineEdit" name="lineEdit"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="btnSenf">
|
<widget class="QPushButton" name="btnSend">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>发送</string>
|
<string>发送</string>
|
||||||
</property>
|
</property>
|
||||||
@ -96,7 +96,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>561</width>
|
||||||
<height>25</height>
|
<height>25</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -108,9 +108,63 @@
|
|||||||
<attribute name="toolBarBreak">
|
<attribute name="toolBarBreak">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
<addaction name="actConnect"/>
|
||||||
|
<addaction name="actDisconnect"/>
|
||||||
|
<addaction name="actClear"/>
|
||||||
|
<addaction name="actQuit"/>
|
||||||
</widget>
|
</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>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="resource.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</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