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;
相关推荐
凉、介5 小时前
深入 QEMU Guest Agent:虚拟机内外通信的隐形纽带
c语言·笔记·学习·嵌入式·虚拟化
njsgcs6 小时前
SIMA2 论文阅读 Google 任务设定器、智能体、奖励模型
人工智能·笔记
云半S一7 小时前
pytest的学习过程
经验分享·笔记·学习·pytest
AI视觉网奇7 小时前
ue5.7 配置 audio2face
笔记·ue5
崎岖Qiu9 小时前
【OS笔记35】:文件系统的使用、实现与管理
笔记·操作系统·存储管理·文件系统·os
曦月逸霜10 小时前
离散数学-学习笔记(持续更新中~)
笔记·学习·离散数学
hunter145010 小时前
windows server AD域与CA部署证书
笔记
im_AMBER10 小时前
Leetcode 101 对链表进行插入排序
数据结构·笔记·学习·算法·leetcode·排序算法
laplace012310 小时前
# 第四章|智能体经典范式构建 —— 学习笔记(详细版)
笔记·学习
别了,李亚普诺夫10 小时前
PCB设计大师篇笔记
笔记·嵌入式硬件·学习