I'm integrating socket comms into a dialog, and have a question about ensuring that all data was sent when using QTcpSocket::write. My approach to this is the following:
- When meaning to send (say, a QByteArray), call QTcpSocket::write
- Connect a slot to the bytesWritten signal, where I increment an internal counter with the amount of bytes sent so far, and if bytesToWrite() == 0, more data needs to be sent
- When sending "more data", use the counter to index into the buffer to send the rest of it.
- The previous two steps will be invoked over and over until all data is sent.
Is this the correct way of ensuring the whole buffer gets sent eventually? Is there an easier way?
Thanks in advance
Bookmarks