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. Qthread or Qtimer is better.
Forum Updated to NodeBB v4.3 + New Features

Qthread or Qtimer is better.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 2.3k Views 1 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.
  • X Offline
    X Offline
    xmaze
    wrote on last edited by
    #1

    Hi, i have an App with QT and i want every 1ms check if exist a querie to send some data to UART.
    Is it better to trigger the function with Qtimer or to make a thread to run in background ?
    I used the Qtimer but i think my processor is on fire!

    Thnx!

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      1ms is overkill...
      beside when you are not on a realtime system you can't ensure 1ms precision.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        As raven-worx pointed out, 1ms is not a good idea.

        And to answer your question: use QTimer if it does not eat up too much of your main thread (the application runs smoothly), otherwise you can consider a thread - but then still you need a QTimer in there, to control the frequency of query checks.

        (Z(:^

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xmaze
          wrote on last edited by
          #4

          i am not sure if i need Qtimer.

          I want to check if a frame needs to transmitted and independence from the individual period of the frame. if the user wants a periodic frame every 3 ms, then the program needs to check if its time to send it.

          For this reason, Qtimer or thread?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rondog
            wrote on last edited by
            #5

            I would use a thread. You can call the msleep(3) function between sending frames in a loop. (i.e. <send><sleep><send><sleep> ...)

            You might even be able to automatically calibrate the sleep time interval if you can measure how much time it takes to build and send the frame (to a resolution of 1ms which may not be good enough)

            I don't know if you can achieve 3ms time periods reliably if you are trying to build something to auto calibrate. To measure you will need a high resolution timer (for example, GetTickCount() in windows has a resolution of 10-16ms which is not good enough).

            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