QTcpSocket state always connected, even unplugging ethernet wire

前端 未结 4 1472
-上瘾入骨i
-上瘾入骨i 2020-12-08 01:11

I have a QTcpSocket and I am reading into a loop. Each time a full packet has been read, or there has been an error, I manually check the status of the socket inside the loo

4条回答
  •  臣服心动
    2020-12-08 01:31

    try this signal slot connection:

    connect(this, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(onStateChanged(QAbstractSocket::SocketState)));

    at slot implementation:

    void TCPWorker::onStateChanged(QAbstractSocket::SocketState socketState ){
    qDebug()<< "|GSTCPWorkerThread::onStateChanged|"<

    I have the same problem, but instead your problem ( always connected ), i have delay 4-5 seconds to receive disconnect signals, after unplugget ethernet wire.

    Still looking solution, post answer if find.

提交回复
热议问题