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;
相关推荐
charlie1145141915 分钟前
嵌入式的现代C++教程——constexpr与设计技巧
开发语言·c++·笔记·单片机·学习·算法·嵌入式
童话名剑12 分钟前
锚框 与 完整YOLO示例(吴恩达深度学习笔记)
笔记·深度学习·yolo··anchor box
2301_783360132 小时前
关于RNAseq——从fastq到gene_counts全流程
笔记·学习
_李小白2 小时前
【AlohaMini学习笔记】第三天:AlohaMini相关技术
笔记·学习
yatingliu20193 小时前
将深度学习环境迁移至老旧系统| 个人学习笔记
笔记·深度学习·学习
week_泽3 小时前
第1课:AI Agent是什么 - 学习笔记_1
人工智能·笔记·学习
Jia shuheng4 小时前
STM32的一键下载CH340 DTR RTS与复位电路NRST的学习笔记
笔记·stm32·学习
wdfk_prog4 小时前
[Linux]学习笔记系列 -- 内核支持与数据
linux·笔记·学习
箫笙默4 小时前
Vue3基础笔记
笔记·vue·vue3
今儿敲了吗4 小时前
01|多项式输出
c++·笔记·算法