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. Is there a way to give a piece of code high priority in Qt?

Is there a way to give a piece of code high priority in Qt?

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

    I have a single-threaded Qt GUI app from where I'll need to read (periodically) some hardware inputs. The application takes some time to process the event loop, so I'm afraid of losing some input events if I rely on QTimer or something like that.

    On a microcontroller running bare metal I would use a hardware timer and an interrupt service routine. But I don't know how to get a similar solution on a higher level environment like Qt.

    The only thing that comes to my mind are threads, but before diving into concurrency issues I decided to come here and ask you if Qt have some other way of solving that problem.

    What I need is to make sure a function runs periodically with an interval of ~10 or 20ms.

    Kent-DorfmanK jsulmJ 2 Replies Last reply
    0
    • R rrd0

      I have a single-threaded Qt GUI app from where I'll need to read (periodically) some hardware inputs. The application takes some time to process the event loop, so I'm afraid of losing some input events if I rely on QTimer or something like that.

      On a microcontroller running bare metal I would use a hardware timer and an interrupt service routine. But I don't know how to get a similar solution on a higher level environment like Qt.

      The only thing that comes to my mind are threads, but before diving into concurrency issues I decided to come here and ask you if Qt have some other way of solving that problem.

      What I need is to make sure a function runs periodically with an interval of ~10 or 20ms.

      Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      @rrd0 said in Is there a way to give a piece of code high priority in Qt?:

      On a microcontroller running bare metal I would use a hardware timer and an interrupt service routine. But I don't know how to get a similar solution on a higher level environment like Qt.

      You dont...or at least you cannot guarantee the RTOS behaviour with Qt. The general answer is "it depends". 10-20ms is not a particularly tight timing constraint, but directly reading hardware registers from within Qt is IMHO, not appropriate.

      If you meet the AI on the road, kill it.

      1 Reply Last reply
      0
      • R rrd0

        I have a single-threaded Qt GUI app from where I'll need to read (periodically) some hardware inputs. The application takes some time to process the event loop, so I'm afraid of losing some input events if I rely on QTimer or something like that.

        On a microcontroller running bare metal I would use a hardware timer and an interrupt service routine. But I don't know how to get a similar solution on a higher level environment like Qt.

        The only thing that comes to my mind are threads, but before diving into concurrency issues I decided to come here and ask you if Qt have some other way of solving that problem.

        What I need is to make sure a function runs periodically with an interval of ~10 or 20ms.

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

        @rrd0 I suggest to use a second thread where you use a QTimer and only communicate with the hardware. I would not use main (GUI) thread for such time critical things.

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

        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