Important: Please read the Qt Code of Conduct -

Problem with sockets

  • Hi,

    I have to communicate with a server using sockets and fetch some data that are URL-encoded. Some of the data I must read is a URL value. It can assume two forms:

    In the second case (and only in it!), when I fetch the data using QTcpSockets, the data seems to be corrupted. When QTcpSocket reads the data that I receive as when I test the protocol using a telnet client, it puts some characters in some places of the string and breaks the URL encoding.

    Using a Telnet connection I can get the right values. When I use QTcpSocket to fetch the data it gets corrupted with some non-printing characters that break the correct decoding.

    My readyData() signal is processed with this slot:

    @void ConnectionHandler::readReply() {
    QByteArray serverReplyArray;
    while (socket->canReadLine()) {

    if (!serverReplyArray.isEmpty()) {
        emit serverReply(serverReplyArray);


    Any tip?

  • I had similar task but my data was not only string but also binary so I wrote code for transmitting data using QTcpSocket::write() and QTcpSocket::readAll(). The data itself was QByteArray with some other types stored in it with QDataStream.
    Since this way seems redundant for your task could you provide minimal working example?

Log in to reply