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;
相关推荐
做cv的小昊15 小时前
【TJU】信息检索与分析课程笔记和练习(1)认识文献
经验分享·笔记·学习·搜索引擎·全文检索
读创商闻16 小时前
崇明岛西滩湿地:离都市最近的候鸟观测笔记
笔记
蒙奇D索大16 小时前
【11408学习记录】考研英语长难句拆解三步法:三步拆解2020年真题,攻克阅读难点
笔记·学习·考研·改行学it
悠闲漫步者16 小时前
第2章 MCS-51单片机的串口和最小系统(学习笔记)
笔记·学习·51单片机
莫白媛16 小时前
Linux创作笔记综合汇总篇
linux·运维·笔记
Wpa.wk17 小时前
Tomcat的安装与部署使用 - 说明版
java·开发语言·经验分享·笔记·tomcat
Vincent_Zhang23317 小时前
专题:所有状语类型(持续补充)
笔记
wdfk_prog17 小时前
[Linux]学习笔记系列 -- [fs]buffer
linux·笔记·学习
海奥华217 小时前
进程调度算法 笔记总结
linux·运维·服务器·笔记·学习
即将进化成人机18 小时前
验证码生成 + Redis 暂存 + JWT 认证
数据库·redis·笔记