If you want to keep your current logic, you’ll need to add a blocking call like responder.socket()->waitForBytesWritten(-1); right after writeChunk.
However, I think that's not a very good idea.
A better way would be to open the file and use the QTcpSocket::bytesWritten event to send data chunk by chunk to the client. It would look something like this:
QTcpSocket *socket = responder.socket(); QObject::connect(socket, &QTcpSocket::bytesWritten, socket, [socket, file, responder = std::move(responder)]() mutable { if (file->atEnd()) { responder.done(); file->deleteLater(); return; } QByteArray chunk = file->read(1024); socket->write(chunk); }); // Send the first chunk right away QByteArray chunk = file->read(1024); socket->write(chunk);This way, you avoid blocking the event loop and can handle multiple clients much more efficiently.