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;
相关推荐
Flittly7 小时前
【SpringAIAlibaba新手村系列】(16)调用百度 MCP 服务
java·笔记·spring·ai·springboot
瑶光守护者8 小时前
【一文读懂】OpenClaw系统架构分析:自主人工智能智能体的范式迁移与技术底座分析
人工智能·笔记·学习·系统架构·边缘计算·openclaw
锦瑟弦音9 小时前
金蝶二开笔记&&setCancelMessage
笔记
_李小白9 小时前
【OSG学习笔记】Day 45: osg::Camera::DrawCallback (抓取图片)
笔记·学习
Java面试题总结10 小时前
2026年Java面试题最新整理,附白话答案
java·开发语言·jvm·笔记·spring·intellij-idea
Westward-sun.10 小时前
OpenCV + dlib 人脸关键点检测学习笔记(68点)
人工智能·笔记·opencv·学习·计算机视觉
chushiyunen10 小时前
阿里云部署dify笔记
笔记·阿里云·云计算
大邳草民10 小时前
Python 对象模型与属性访问机制
开发语言·笔记·python
kinl201811 小时前
cs2385_note5 (lec18-lec19) Variational Inference & Control as Inference
笔记
智者知已应修善业12 小时前
【51单片机非精准计时2个外部中断启停】2023-5-29
c++·经验分享·笔记·算法·51单片机