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 with value of 0
Forum Updated to NodeBB v4.3 + New Features

QTimer with value of 0

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 817 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.
  • Q Offline
    Q Offline
    qttester5
    wrote on last edited by
    #1

    Do I understand correctly that if you set a QTimer with a value of 0 and upon its timeout you run a function, that basically what is happening is that the function will run on the same thread that called the timer, usually GUI, but that it will essentially not run the function until any UI events have been processed first, is that correct?

    This strategy pops up occasionally when reading about threads, but as far as I can tell, it is not actually processing anything on another thread, right?

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      [quote author="qttester5" date="1397472767"]Do I understand correctly that if you set a QTimer with a value of 0 and upon its timeout you run a function, that basically what is happening is that the function will run on the same thread that called the timer[/quote]No. It depends on 2 things:

      • The "thread affinity":http://qt-project.org/doc/qt-5/qobject.html#thread-affinity of the receiver object.
      • The "ConnectionType":http://qt-project.org/doc/qt-5/qt.html#ConnectionType-enum

      This is the same for all signal-slot connections.

      [quote]it will essentially not run the function until any UI events have been processed first, is that correct?[/quote]If there are no events to process in the slot thread, the function will run immediately when the timer times out.

      If the slot thread is in the middle of processing events when the timer times out, the thread will finish processing all pending events and then run the function.

      [quote]This strategy pops up occasionally when reading about threads[/quote]I wouldn't do this. If your timer is repetitive, your thread will try to run the function repeatedly as fast as possible -- your CPU core will be maxed out.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      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