QtExamples/QtTcpEx/ExTcpClient/ExTcpClient.cpp

52 lines
920 B
C++
Raw Normal View History

#include "ExTcpClient.h"
#include "ui_ExTcpClient.h"
ExTcpClient::ExTcpClient(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::ExTcpClient)
{
ui->setupUi(this);
}
ExTcpClient::~ExTcpClient()
{
delete ui;
}
2019-11-23 00:03:15 +08:00
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();
}