문제

I have created a (somewhat) simple telnet server, which creates a new thread for each connection:

void TelnetServer::incomingConnection(qintptr socketDescriptor)
{
    TelnetConnection *thread = new TelnetConnection(socketDescriptor, this);
    connect(thread, SIGNAL(shutdownRequested()), m_controller, SLOT(shutdown()));
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    thread->start();
}

After I disconnect the telnet client, I expected the deleteLater() slot to be called. However, findchildren of the telnet server shows that my QThread object for the (just disconnected) session still exists. It's as if the finished signal were not emitting.

As an experiment I tied the finished signal to a function that Qdebug's "FINISHED"...and it never appears. Can someone explain why the finished signal is not emitting after I disconnect the telnet client?


I am assuming that calling thread.disconnectClient() terminates the thread...but perhaps that's an incorrect assumption? To I have to quit the exec loop for the thread?

도움이 되었습니까?

해결책

If you disconnect a running thread, and you do not have proper treatment, the finished signal is not supposed to be called, so this is normal.

You could hook up the delete later or the disconnect "signal" that you establish, but you need to make sure to properly quit the thread.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top