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. QThreads and QSerialPort

QThreads and QSerialPort

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 252 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.
  • Dharani PrasadD Offline
    Dharani PrasadD Offline
    Dharani Prasad
    wrote on last edited by Dharani Prasad
    #1

    Hello all,
    I'm a Qt beginner. I have tried reading and writing data to Arduino using Serialport. It works fine.
    Now, I want to implement the same using threads and I wanna know that is there any options available to embed Serialport functionalities in threads or any other suggestions would help.

    I tried searching resources which would help me in this topic, But I couldn't find any.

    Thanks in advance! : )

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

      Hi
      Yes you can use QSerialPort in a thread but do you really need it ?
      It's asynchronous already meaning it won't pause your app while reading.

      However, sometimes the processing of the incoming data takes up too much time
      and hence this processing could be moved to a thread.

      However, if just for leaning here is one example
      https://evileg.com/en/post/290/

      Note its using the blocking api of serialport. not the signal based.

      Here they use the signals in a class called SerialWorker that runs in a thread

      https://www.programmersought.com/article/93167931470/

      sorry for all the ads. The code is fine though.

      You can just grab the SerialWorker class and use.

      Do note that from another thread, you are not not allowed to touch any widget in the main GUI.

      So if you want to update anything ui->xxxxx it has to be done via signals and slot. not via pointers into
      Mainwindow.

      Dharani PrasadD 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        Yes you can use QSerialPort in a thread but do you really need it ?
        It's asynchronous already meaning it won't pause your app while reading.

        However, sometimes the processing of the incoming data takes up too much time
        and hence this processing could be moved to a thread.

        However, if just for leaning here is one example
        https://evileg.com/en/post/290/

        Note its using the blocking api of serialport. not the signal based.

        Here they use the signals in a class called SerialWorker that runs in a thread

        https://www.programmersought.com/article/93167931470/

        sorry for all the ads. The code is fine though.

        You can just grab the SerialWorker class and use.

        Do note that from another thread, you are not not allowed to touch any widget in the main GUI.

        So if you want to update anything ui->xxxxx it has to be done via signals and slot. not via pointers into
        Mainwindow.

        Dharani PrasadD Offline
        Dharani PrasadD Offline
        Dharani Prasad
        wrote on last edited by
        #3

        @mrjj Thank you, I will take a look on these links

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