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. QTimer in QThread. How?
Forum Update on Monday, May 27th 2025

QTimer in QThread. How?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.0k 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

    Hello all!
    I've got stacked by simple issue. I need to implement QTimer in QThread and start and stop QTimer from another QThread. Officially in doc not possible to do it directly for QTimer from outside thread. I've been solving somehow it before, but I don't remember in precise how to do it. I remember only that was something about loop and making it through flag-system and onetime-timer inside of QThread. Could any one help me? Or correct me for simpler way of it.

    jsulmJ 1 Reply Last reply
    0
    • B bogong

      Hello all!
      I've got stacked by simple issue. I need to implement QTimer in QThread and start and stop QTimer from another QThread. Officially in doc not possible to do it directly for QTimer from outside thread. I've been solving somehow it before, but I don't remember in precise how to do it. I remember only that was something about loop and making it through flag-system and onetime-timer inside of QThread. Could any one help me? Or correct me for simpler way of it.

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

      @bogong said in QTimer in QThread. How?:

      and stop QTimer from another QThread

      Use signals/slots between these two threads with queued connection type. In the thread where the timer is living you implement a slot and connect it to a signal from the second one.

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

      1 Reply Last reply
      2
      • B Offline
        B Offline
        bogong
        wrote on last edited by bogong
        #3

        @jsulm Am I right about understanding of it by this example?

        jsulmJ 1 Reply Last reply
        0
        • B bogong

          @jsulm Am I right about understanding of it by this example?

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

          @bogong Yes, it does what I suggested. Doing it this way means that the timer is only accessed in the thread where it lives. Other threads only ask the timer thread to do something with the timer.

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

          B 1 Reply Last reply
          0
          • jsulmJ jsulm

            @bogong Yes, it does what I suggested. Doing it this way means that the timer is only accessed in the thread where it lives. Other threads only ask the timer thread to do something with the timer.

            B Offline
            B Offline
            bogong
            wrote on last edited by bogong
            #5

            @jsulm Solution found. There was the error in example. I've been doing QThread inheritance but all of QTimer wasn't in run() function therefore it was running in main thread. Corrected version just published. Thx for assistance and refreshing memory.

            Issue closed.

            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