c++ QTcpServer

cpp:

cpp 复制代码
   server = new QTcpServer(this);
    connect(server, &QTcpServer::newConnection, this, &PythonConsole::newConnection);
    if (!server->listen(QHostAddress::Any, 8000)) {
        qWarning("Unable to start the server: %s", qPrintable(server->errorString()));
    }

调试:

cpp 复制代码
    connect(server, &QTcpServer::newConnection, [this]() {
        QTcpSocket *socket = server->nextPendingConnection();
        qDebug() << "New connection from:" << socket->peerAddress().toString();
    });
cpp 复制代码
void PythonConsole::newConnection()
{
    clientConnection = server->nextPendingConnection();
    connect(clientConnection, &QTcpSocket::readyRead, this, &PythonConsole::readClient);
}

void PythonConsole::readClient()
{
    QByteArray data = clientConnection->readAll();
    QString command = QString::fromUtf8(data);
    runSource(command);
    clientConnection->close();
}

h:

cpp 复制代码
    QTcpServer *server;
    QTcpSocket *clientConnection;
相关推荐
赶飞机偏偏下雨26 分钟前
【Java笔记】消息队列
java·开发语言·笔记
黎宇幻生8 小时前
Java全栈学习笔记39
java·笔记·学习
遇印记11 小时前
大二java学习笔记:二维数组
java·笔记·学习
bnsarocket13 小时前
Verilog和FPGA的自学笔记6——计数器(D触发器同步+异步方案)
笔记·fpga开发·verilog·自学·硬件编程
LK_0714 小时前
【Open3D】Ch.3:顶点法向量估计 | Python
开发语言·笔记·python
li星野14 小时前
打工人日报#20251011
笔记·程序人生·fpga开发·学习方法
摇滚侠14 小时前
Spring Boot 3零基础教程,yml配置文件,笔记13
spring boot·redis·笔记
QT 小鲜肉14 小时前
【个人成长笔记】在Ubuntu中的Linux系统安装 anaconda 及其相关终端命令行
linux·笔记·深度学习·学习·ubuntu·学习方法
QT 小鲜肉14 小时前
【个人成长笔记】在Ubuntu中的Linux系统安装实验室WIFI驱动安装(Driver for Linux RTL8188GU)
linux·笔记·学习·ubuntu·学习方法
急急黄豆15 小时前
MADDPG学习笔记
笔记·学习