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 Updated to NodeBB v4.3 + New Features

QTimer in QThread. How?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 2.1k 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 16 Oct 2019, 08:42 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.

    J 1 Reply Last reply 16 Oct 2019, 08:45
    0
    • B bogong
      16 Oct 2019, 08:42

      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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 16 Oct 2019, 08:45 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 16 Oct 2019, 08:48 last edited by bogong
        #3

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

        J 1 Reply Last reply 16 Oct 2019, 08:57
        0
        • B bogong
          16 Oct 2019, 08:48

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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 16 Oct 2019, 08:57 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 16 Oct 2019, 09:58
          0
          • J jsulm
            16 Oct 2019, 08:57

            @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 16 Oct 2019, 09:58 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

            1/5

            16 Oct 2019, 08:42

            • Login

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