Network-chat example: Only disconnect if still connected

If we are already disconnected we end up printing warnings about how it's
illegal to call waitForBytesWritten on an unconnected socket

Change-Id: I8c864d105d5372edfee84affb362cca3021b8ea0
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mårten Nordheim 2023-06-14 20:30:00 +02:00
parent 5a6f51a322
commit 0471df7987

View File

@ -48,7 +48,7 @@ Connection::Connection(qintptr socketDescriptor, QObject *parent)
Connection::~Connection()
{
if (isGreetingMessageSent) {
if (isGreetingMessageSent && QAbstractSocket::state() != QAbstractSocket::UnconnectedState) {
// Indicate clean shutdown.
writer.endArray();
waitForBytesWritten(2000);