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;
相关推荐
周周记笔记2 小时前
学习笔记:第一个Python程序
笔记·学习
丑小鸭是白天鹅2 小时前
Kotlin协程详细笔记之切线程和挂起函数
开发语言·笔记·kotlin
潘达斯奈基~2 小时前
《大数据之路1》笔记2:数据模型
大数据·笔记
..过云雨3 小时前
05.【Linux系统编程】进程(冯诺依曼体系结构、进程概念、进程状态(注意僵尸和孤儿)、进程优先级、进程切换和调度)
linux·笔记·学习
咸甜适中3 小时前
rust语言 (1.88) egui (0.32.2) 学习笔记(逐行注释)(二十八)使用图片控件显示图片
笔记·学习·rust·egui
一又四分之一.3 小时前
高数基础知识(下)②
笔记
ZHANG8023ZHEN4 小时前
fMoE论文阅读笔记
论文阅读·笔记
Ro Jace4 小时前
文献阅读笔记:R&S电子战测试与测量技术文档
笔记
ZZHow10245 小时前
Maven入门_简介、安装与配置
java·笔记·maven
芜狄8 小时前
UCOSIII移植——学习笔记1
笔记·嵌入式硬件·学习·stm32f103rct6·ucosiii实时操作系统