Pergunta

I was programming a server, I programmed the service and a manager. When I stop the server with the UI Server Manager, the server calls a function called "stopServer()", that function contains the following:

qDebug() << "Stopping the server...";
// Clear the vector and free the memory by deleting pointers
qDebug() << clients.size();
for(int i=0;i<clients.size();i++){
    clients.get(i)->getSocket()->flush();
    clients.get(i)->getSocket()->close();
    clients.get(i)->getSocket()->disconnectFromHost();
    clients.get(i)->getSocket()->waitForDisconnected(3);
}
clients.destroy();
// Close the server
socket_server->close();
// Stop the handler
qDebug() << "Stopped.";

Actually, that "clients" variable it's only a vector that contains the user data, he close the QTcpSocket for each connection, and then clean the clients variable and reset it to 0.

When I have one connection on the server (the UI Manager works as one of that connection), and I try to stop it, it fails. I removed that vector system. And it's stills not working, it don't give me any error, just crashes the application.

If you need all the code, just tell me!

(Sorry for my bad english...)

Update: If I remove "socket_server->close()" it works without any problem. Update #2: It seems that it's a problem with a pointer deletion. Idk....

SOLVED: Omg I was a dumb! socket_server was a null pointer... I just fixed that, and that's it!

Foi útil?

Solução

Omg I was a dumb! socket_server was a null pointer... I just fixed that, and that's it!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top