Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Correct Way to handle SerialPort messages

Correct Way to handle SerialPort messages

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 574 Views
  • 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.
  • DiogoPereira98D Offline
    DiogoPereira98D Offline
    DiogoPereira98
    wrote on last edited by
    #1

    Hello, I'm a student developing a UI that reads and sends CAN messages via Serial Port. Some of the code was done by other students in the past and I have some doubts about the correct way to handle incoming messages.

    So currently our serial port class reads the message, places it in a queue and signals the presence of a new message, and the class that sends the messages to our widgets runs a slot called pop that dequeues one message from the serial port class. My question is, would it be worse to send the message directly through the signal to our widgets, with no pop function? (like this: "emit new_message(CANdata msg);" CANdata is a struct)

    Thank you for your time.

    aha_1980A 1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      It is done to ensure that your UI not locked because of message processing. What they are doing is best practice. Not sure how your project is organised. If UI in one thread and Serial message reading in another thread, you can simply use the signal/slots. Queue is automatically care by the Qt itself.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • DiogoPereira98D DiogoPereira98

        Hello, I'm a student developing a UI that reads and sends CAN messages via Serial Port. Some of the code was done by other students in the past and I have some doubts about the correct way to handle incoming messages.

        So currently our serial port class reads the message, places it in a queue and signals the presence of a new message, and the class that sends the messages to our widgets runs a slot called pop that dequeues one message from the serial port class. My question is, would it be worse to send the message directly through the signal to our widgets, with no pop function? (like this: "emit new_message(CANdata msg);" CANdata is a struct)

        Thank you for your time.

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @DiogoPereira98 the best you can do here is: measure. I doubt the queue is really needed, as serial ports are slow. I would add some debug outputs tracing when queue is enqueued/dequeued and how big it is.

        If it rarely goes over 1...5 elements, its probably not needed.

        Otoh, never change a running code ;)

        Qt has to stay free or it will die.

        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 Extensions
        • Unsolved