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. Parallel thread to read coming data
Forum Update on Monday, May 27th 2025

Parallel thread to read coming data

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 6 Posters 466 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.
  • A Offline
    A Offline
    Andrew23
    wrote on last edited by
    #1

    I never managed concurrent threads in Qt but now I need a function in my application to monitor the presence of available data coming from an FTDI device (I'm using the FDTI driver to read/write data). I need a for loop that run every few millisecond to check if there are bytes in the receive queue and thet run concurrently with the application. If there are bytes in the receive queue then emits a signal for the main thread.

    I read some example about the Concurrent library but I can't achieve my purpose cause I am not familiar with this stuff. Can someone help me or get me some suggestion ?

    jsulmJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Don't use QtConcurrent but a simple QThread and run your loop inside the run() function.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • A Andrew23

        I never managed concurrent threads in Qt but now I need a function in my application to monitor the presence of available data coming from an FTDI device (I'm using the FDTI driver to read/write data). I need a for loop that run every few millisecond to check if there are bytes in the receive queue and thet run concurrently with the application. If there are bytes in the receive queue then emits a signal for the main thread.

        I read some example about the Concurrent library but I can't achieve my purpose cause I am not familiar with this stuff. Can someone help me or get me some suggestion ?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Andrew23 said in Parallel thread to read coming data:

        I need a for loop that run every few millisecond

        A QTimer should be enough for this, no need for a thread.

        If you really need a thread then use the worker object approach like shown here: https://doc.qt.io/qt-6/qthread.html
        If something does not work/is unclear ask a more specific question.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #4

          Have you looked into QSocketNotfier or QFile?

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on last edited by
            #5

            Just use: https://www.ftdichip.com/Support/Knowledgebase/index.html?ft_seteventnotification.htm

            A 1 Reply Last reply
            0
            • K kuzulis

              Just use: https://www.ftdichip.com/Support/Knowledgebase/index.html?ft_seteventnotification.htm

              A Offline
              A Offline
              Andrew23
              wrote on last edited by Andrew23
              #6

              Thanks everyone for your suggestions.

              @kuzulis I want to use it but I don't know how to use it in my application. I'm newbie with this kind of stuff. I found this post but without response. Can you show me an example to how use the FT_SetEventNotification?

              1 Reply Last reply
              0
              • mrdebugM Offline
                mrdebugM Offline
                mrdebug
                wrote on last edited by mrdebug
                #7

                Hi, if you have only to display what is coming in you don't need a thread. I suggest to use a thread only if you have a machine state related to the external device.
                If you want to use a thread, when something is come in you only have to emit a event to update the gui.
                Please have a look at emit and slot features and the event cnnection types.
                A suggestion: if you use a thread please use syncronized methods to read and write the uart.

                Need programmers to hire?
                www.labcsp.com
                www.denisgottardello.it
                GMT+1
                Skype: mrdebug

                A 1 Reply Last reply
                0
                • mrdebugM mrdebug

                  Hi, if you have only to display what is coming in you don't need a thread. I suggest to use a thread only if you have a machine state related to the external device.
                  If you want to use a thread, when something is come in you only have to emit a event to update the gui.
                  Please have a look at emit and slot features and the event cnnection types.
                  A suggestion: if you use a thread please use syncronized methods to read and write the uart.

                  A Offline
                  A Offline
                  Andrew23
                  wrote on last edited by
                  #8

                  @mrdebug I don't need to update the gui. I need to receive data in a state machine and handle the comunication protocol packets. And I'm not using UART, I'm using the FTDI driver.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kuzulis
                    Qt Champions 2020
                    wrote on last edited by kuzulis
                    #9

                    Can you show me an example to how use the FT_SetEventNotification?

                    1. Just create an event handle (via CreateEvent ... as mention in FTDI doc).
                    2. Configure event notification mask (via FT_SetEventNotification, FT_EVENT_RXCHAR ... as mention in FTDI doc).
                    3. Use QWinEventNotifier class https://doc.qt.io/qt-6/qwineventnotifier.html to watch when the FT_EVENT_RXCHAR event triggered.
                    4. When the event triggeres, fetch the reason (via FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord); )
                    5. If RxBytes > 0 then read the data (as mention in FTDI doc).

                    That's all,

                    1 Reply Last reply
                    1

                    • Login

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