1

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!

harper
  • 13,345
  • 8
  • 56
  • 105
Spamdark
  • 1,341
  • 2
  • 19
  • 38
  • 3
    Instead of editing the title to include the word "solved", please post an answer and mark it "accepted". This will prevent the question from showing up when displaying unanswered questions. – Arnold Spence Nov 08 '12 at 00:53
  • Arnold is correct. If you've solved the problem, answer the question and accept it. –  Nov 08 '12 at 00:59
  • Just hint for future: If your code crashed, use debugger! If you still can't see anything usefull in debugger then ask question (code + debugger report) – Kamil Klimek Nov 08 '12 at 12:53

1 Answers1

0

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

Spamdark
  • 1,341
  • 2
  • 19
  • 38