コード例 #1
0
void Server::incomingConnection(int id)
{
    QThread* thread = new QThread();
    ServerSocket* socket = new ServerSocket(id);
    socket->moveToThread(thread);
    thread->start();
    connect(thread, SIGNAL(finished()),
            thread, SLOT(deleteLater()));
    connect(socket, SIGNAL(logGenerated(QString)),
            this, SLOT(on_socket_logGenerated(QString)));
    connect(socket, SIGNAL(imageRead(QByteArray)),
            this, SLOT(on_socket_imageRead(QByteArray)));
    connect(this, SIGNAL(serverTerminated()),
            socket, SLOT(disconnectFromHostImplementation()));
    connect(this, SIGNAL(serverTerminated()),
            socket, SLOT(abortConnection()));
    connect(socket, SIGNAL(disconnected()),
            thread, SLOT(quit()));   //Seems risky
}