Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with sockets
Qt 6.12 LTS is out! See what's new in the release blog

Problem with sockets

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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:

    • A simple URL, like http://www.google.com, that comes as "http://www.google.com"
    • A URL containing another URL for redirection, like http://www.someurl.com/foo?bar=http://www.redirecttohere.com, that comes encoded as http://www.someurl.com/foo?bar=http%3A%2F%2Fwww.redirecttohere.com

    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 http://www.someurl.com/foo?bar=http%3A%2F%2Fwww.redirecttohere.com 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()) {
    serverReplyArray.append(socket->readLine().trimmed());
    }

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

    }@

    Any tip?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt
      • Unsolved