Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

signal slot in sperate threads



  • hi,

    I read a lot about signal slot mechanism, types of connections, and priority.

    I have simple example of ui main thread , controller thread and udp thread.

    The udp thread read the data with signal-slot readyread.

    I have other app that send the data in some different rates to test the performance.

    I added on the the data that i send a counter that i inc on every send.

    I have an issue that I don't know how to explain, i need help.

    **when i press with the mouse on the UI (anywhere on the form) , or only move the form , the udp thread lose packets , it seems that the udp thread is waiting to the events of the ui to finish.

    why there is any connection between the threads ??

    when I receive the data with while(1) and waitForReadyRead i don't lose packets **


  • Qt Champions 2019

    @Lior said in signal slot in sperate threads:

    why there is any connection between the threads ??

    Why do you think there is a connection? If you did not connect both threads (signals/slots for example) in some way then there is no connection.
    First thing: UDP does not guarantee that everything arrives, use TCP if you need this guarantee.
    Then: what does your UI thread do? Do you have any code executed if you click on your UI? Does the UDP thread send data to the UI and if so does it wait for the UI to process it?

    You also could post your UDP and UI thread implementation , it would probably help more than just a description.



  • Hi, I will create a small example to my question above.

    For the mean time I read about the move to a thread and I reorganized the code.
    I think I used not correctly the thread creation and connecting signals.

    I understood that if I not using the move to thread the QObject that register to the signals (events) is the parent thread and therefore the mechanism is not working.

    The signal-slot documentation is not very clear and I have a lot of questions about multithresding.

    "Why do you think there is a connection?" - when i press on the UI i losing lots of packets. its clearly that the ui blocking the UDP thread.

    "UDP does not guarantee that everything arrives" i agrre, but the socket is on localhost, so basicly if the computer is not super busy i shuld not lose packets , and when i press on the UI, im losing lots of packets (more the 100).


Log in to reply