Hello! I'm using QTcpSocket to send messages to a remote server.
Here's a quick example to give you a heads-up:

Qt Code:
  1. Myclass::Myclass(QWidget *parent) : QWidget(parent)
  2. {
  3. QTcpSocket *socket = new QTcpSocket; // To know what socket is
  4. // Connect to server and launch session:
  5. socket->connectToHost("server.example.com",12345);
  6. socket->write("Session: self;Start");
  7. // OK, Session is connected.
  8. // If I call this:
  9. socket->write("Session: self; Disconnect");
  10. // The session closes successfully.
  11. }
To copy to clipboard, switch view to plain text mode 
However...
Qt Code:
  1. Myclass::~Myclass() {
  2. socket->write("Session: self; Disconnect");
  3. qDebug() << "Program closing...";
  4. }
To copy to clipboard, switch view to plain text mode 

On closing my application (Alt+F4, closing the window), the debug console says:
Program closing...
but the socket is not sending the message to the server and my session remains opened.

If I do this:

Qt Code:
  1. Myclass::~Myclass()
  2. {
  3. socket->write("Session: this; Disconnect");
  4. QMessageBox::warning(this,"Closing", "Program is closing...");
  5. qDebug() << "Program closed.";
  6. }
To copy to clipboard, switch view to plain text mode 

And voila, it works. it sends the message, pops up the warning box, and prints the message. Is there a way to make it work without the Messagebox ?