1 Star 0 Fork 47

tianyayouge/SocketTool

forked from c./SocketTool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
tcpserverwidget.cpp 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
#include "tcpserverwidget.h"
#include "ui_tcpserverwidget.h"
TcpServerWidget::TcpServerWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::TcpServerWidget)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
setAttribute(Qt::WA_ShowModal);
setWindowFlags(Qt::Tool);
QIntValidator* portValidator = new QIntValidator(1, 65535, this);
ui->lineEditPort->setValidator(portValidator);
ui->lineEditPort->setText("60000");
ui->comboBox->addItem(tr("Any-address"), "");
QList<QHostAddress> hostAddressList = QNetworkInterface::allAddresses();
foreach (QHostAddress address, hostAddressList)
{
ui->comboBox->addItem(address.toString(), address.toString());
}
}
TcpServerWidget::~TcpServerWidget()
{
delete ui;
}
void TcpServerWidget::on_pushButtonOk_clicked()
{
int port = ui->lineEditPort->text().toInt();
if (ui->lineEditPort->text().isEmpty() || port <= 0)
return;
QString hostAddress = ui->comboBox->currentData().toString();
QObject *p = parent();
if (p != nullptr)
{
QTcpServer* tcpServer = new QTcpServer(p);
if (tcpServer->listen(hostAddress.isEmpty() ? QHostAddress::Any : QHostAddress(hostAddress), port))
{
emit tcpServerCreated(tcpServer);
close();
}
else
{
QString error = QString("Create TCP Server failed! %1").arg(tcpServer->errorString());
QMessageBox::critical(this, tr("Error"), error);
tcpServer->deleteLater();
}
}
}
void TcpServerWidget::on_pushButtonCancel_clicked()
{
close();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/tianyayouge/SocketTool.git
git@gitee.com:tianyayouge/SocketTool.git
tianyayouge
SocketTool
SocketTool
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385