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. Problems with network connection, signals and threads
Qt 6.12 LTS is out! See what's new in the release blog

Problems with network connection, signals and threads

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 593 Views 2 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.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by
    #1

    I have developed a network connection with unittests and in the test everything works as expected.

    Now I put the connection part in the application and there I get problems. It took a while until all event-callbacks were executed in the right thread. Because of the fragmentation of the network transfer by the different signals I store the message in a private member variable. Then in the corresponding callback the member variable is read and sent.

    My problem is that the content of the member variable changes between event callbacks. For this I have set data breakpoints on the variable to find out who is poaching in memory.
    At startup, the data breakpoint hits once at an unexpected place:
    Thread QDBusConnection, Stack QDBusConnectionTypeInfo -> QByteArray

    This is before the variable is even created. The variable is a pointer that is set to 0 in the constructor. Then the first time a message is sent, a QByteArray is created on the pointer and filled with data.
    Then a connection is established with a QTcpSocket (connectToHost). At OnConnected-callback the message should be sent, but now the QByteArray already has a different content.

    I checked if the class is the same instance and if everything happens in the right thread. Then I checked if maybe the destructor is called. None of this is true. There is also no friend declaration that a stranger could use to change the private variable ...

    Now I'm at a loss. How can I find out who is screwing up my memory space and why?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Anything "static" in your design ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        django.Reinhard
        wrote on last edited by
        #3

        Hi and thank you for your attention.

        No static was not the problem.
        But triggered by your question, I found it.

        I built a blocking socket variant and then on debugging I saw, that the message body was clobbered at socket.connectToHost ...

        I treated that possiblity as impossible and started a wider search, which leaded to my fault:
        I used QByteArray::setRawData() and thought, that would copy the source buffer. But that's not true (RTFM). I had to use the constructor with buffer-pointer and buffer size to obtain a deep buffer copy.

        Now it works.

        1 Reply Last reply
        2

        • Login

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