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;
相关推荐
Brilliantwxx1 天前
【C++】 继承与多态(上)
开发语言·c++·笔记·算法
05候补工程师1 天前
【线性代数】核心考点:二次型、矩阵三大关系综合与正定矩阵判别法
笔记·线性代数·考研·算法·矩阵
zcongfly1 天前
Claude code使用笔记
笔记
哎呦,帅小伙哦1 天前
Git Describe 与 TRAVIS_TAG学习笔记
笔记·git·学习
江屿风1 天前
【c++笔记】类和对象流食般投喂(下)
开发语言·c++·笔记
凉、介1 天前
Armv8-A virtualization 笔记 (二)
笔记·学习·嵌入式·arm·gic
智者知已应修善业1 天前
【ICL8038芯片正弦波三角波方波发生器电路】2024-1-5
驱动开发·经验分享·笔记·硬件架构·硬件工程
探序基因1 天前
身高与基因的关系
笔记
llhm1 天前
tsp学习笔记——LINUX SDK编译2(2)Kernel6.1 Linux
linux·笔记·学习
wangcheng3032 天前
关键词优化怎么理解最清楚
笔记