I'm about to write a small server using QTcpServer
which is intended to be connected by e. g. a telnet client. Only text will be sent.
Qt's fortune cookie server example uses a QDataStream
to send text via the following code using a QTcpSocket
:
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_10);
out << "Some Text";
socket->write(block);
If one does not want to send binary data, is there any drawback to send Unicode data directly (everyone involved knows we're using UTF-8) like so:
socket->write(QString::fromUtf8("Some text").toUtf8);
?