I can't understand your code when compared to your flow diagram.
What is this part for?:
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
To copy to clipboard, switch view to plain text mode
Also, I am not sure this slot is a good place for:
QTcpSocket *clientConnection
= tcpServer
->nextPendingConnection
();
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
To copy to clipboard, switch view to plain text mode
Since you assume that every time you get data from what ever socket, there is another pending connection - and there is no assurance for that.
So this code:
QTcpSocket *clientConnection
= tcpServer
->nextPendingConnection
();
clientConnection->write(block);
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
clientConnection->write(block);
To copy to clipboard, switch view to plain text mode
Is probably what is crashing your application, when clientConnection is NULL.
At the very least you should test it first:
if(tcpServer->hasPendingConnections()
{
clientConnection = tcpServer->nextPendingConnection();
clientConnection->write(block);
}
QTcpSocket *clientConnection = NULL;
if(tcpServer->hasPendingConnections()
{
clientConnection = tcpServer->nextPendingConnection();
clientConnection->write(block);
}
To copy to clipboard, switch view to plain text mode
EDIT: beat to it by marcel
Bookmarks