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;
相关推荐
轻闲一号机29 分钟前
【机器学习】机器学习笔记
人工智能·笔记·机器学习
天下琴川1 小时前
Dify智能体平台源码二次开发笔记(5) - 多租户的SAAS版实现(2)
人工智能·笔记
workworkwork勤劳又勇敢3 小时前
Adversarial Attack对抗攻击--李宏毅机器学习笔记
人工智能·笔记·深度学习·机器学习
寻丶幽风4 小时前
论文阅读笔记——Generating Long Sequences with Sparse Transformers
论文阅读·笔记·语言模型·transformer·稀疏自注意力
Angindem4 小时前
websoket 学习笔记
笔记·学习
jackson凌9 小时前
【Java学习笔记】Java第一课,梦开始的地方!!!
java·笔记
I like Code?9 小时前
AntVG2可视化学习与开发笔记-React19(持续更新)
javascript·笔记·学习
那天的烟花雨11 小时前
android display 笔记(十一)surfaceflinger 如何将图层传到lcd驱动的呢?
android·笔记
你说你说你来说11 小时前
安卓开发Intent详细介绍和使用
android·笔记
jingjingjing111111 小时前
笔记:代码随想录算法训练营day67:Floyd 算法精讲、A * 算法精讲 (A star算法) 严重超时完结,不过,撒花
笔记