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;
相关推荐
lkbhua莱克瓦245 分钟前
JavaScript核心语法
开发语言·前端·javascript·笔记·html·ecmascript·javaweb
SmartBrain5 分钟前
Agent 知识总结
服务器·数据库·笔记
杨浦老苏14 分钟前
离线优先的自托管笔记应用Anchor
笔记·docker·群晖
CryptoPP38 分钟前
主流国际股票行情API接口横向对比:如何选择适合你的数据源?
大数据·笔记·金融·区块链
代码游侠1 小时前
嵌入式开发——ARM Cortex-A7内核和i.MX6处理器相关的底层头文件
arm开发·笔记·嵌入式硬件·学习·架构
hetao17338372 小时前
2026-01-19~20 hetao1733837 的刷题笔记
c++·笔记·算法
优雅的潮叭2 小时前
c++ 学习笔记之 volatile与atomic
c++·笔记·学习
宵时待雨3 小时前
STM32笔记归纳2:GPIO
笔记·stm32·嵌入式硬件
代码游侠4 小时前
ARM嵌入式开发代码实践——LED灯闪烁(C语言版)
c语言·开发语言·arm开发·笔记·嵌入式硬件·学习
Aliex_git4 小时前
大模型相关概念 - LLM对话
人工智能·笔记·prompt·ai编程