/* * New client connection */void SenseSystem::TechServer::incomingConnection(qintptr socketDescriptor){ // If server started qDebug() << "New request to connect!!!!!"; QTcpSocket *clientSocket = new QTcpSocket(); socket.insert(socketDescriptor,clientSocket); // Trying to connect to socket descriptor if (!socket[socketDescriptor]->setSocketDescriptor(socketDescriptor)) { // Can't connect to socket descriptor socket[socketDescriptor]->deleteLater(); socket.remove(socketDescriptor); } else { // setup signal and slot connect(socket[socketDescriptor],SIGNAL(readyRead()),this,SLOT(socketReadClient())); // Initiolization settings for system QTimer *timerOut = new QTimer(this); autoriz.insert(socketDescriptor,timerOut); // setup signal and slot connect(autoriz[socketDescriptor],SIGNAL(timeout()),this,SLOT(autorizTimeout())); // Reading command from MySQL autoriz[socketDescriptor]->start(15000); }}
QThread *thread = new QThread(this); clientSocket->moveToThread(thread); Client *client = new Client(clientSocket,sql,IDSystem); client->moveToThread(thread); // Соединяем сигнал started потока, со слотом process "рабочего" класса, т.е. начинается выполнение нужной работы. connect(thread,SIGNAL(started()),client,SLOT(process())); connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater())); // По завершению выходим из потока, и удаляем рабочий класс connect(client,SIGNAL(finished()),thread,SLOT(quit())); connect(client,SIGNAL(finished()),client,SLOT(deleteLater())); // Starting the thread of socket to execute events connect(clientSocket,SIGNAL(readyRead()),client, SLOT(socketReadClient())); connect(clientSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),client, SLOT(clientChangeState())); connect(clientSocket,SIGNAL(error(QAbstractSocket::SocketError)),client, SLOT(socketErrorClient())); connect(clientSocket,SIGNAL(disconnected()),client, SLOT(socketRemoveClient())); // Удаляем поток, после выполнения операции if(config.typeView == CONSOLE) { connect(client,SIGNAL(println(QString)),((Console *)config.display),SLOT(outStream(QString))); connect(client,SIGNAL(addClientToList(qintptr)),((Console *)config.display),SLOT(addClientToList(qintptr))); } else if(config.typeView == WINDOW) { connect(client,SIGNAL(println(QString)),((MainWindow *)config.display),SLOT(outStream(QString))); connect(client,SIGNAL(addClientToList(qintptr)),((MainWindow *)config.display),SLOT(addClientToList(qintptr))); } connect(client,SIGNAL(removeClientFromList(qintptr)),this,SLOT(removeMap(qintptr))); SenseSystem::TechServer::client.insert(socketDescriptor,client); thread->start();