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 and QThread?
Forum Update on Monday, May 27th 2025

QTimer and QThread?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 917 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.
  • C Offline
    C Offline
    CongVo
    wrote on last edited by CongVo
    #1

    What different between QTimer and QThread?
    When we use QTimer instead of QThread?

    I made a shooting game and i have a class bullet.
    each bullet is a pointer . It changes position every 2s.(I used QTimer for it)
    a player shot lots of bullets so my game got lagging so much.
    Is that caused by Timer variables?
    any ideas to solve this issue?
    Thanks alot!

    raven-worxR jsulmJ 2 Replies Last reply
    0
    • C CongVo

      What different between QTimer and QThread?
      When we use QTimer instead of QThread?

      I made a shooting game and i have a class bullet.
      each bullet is a pointer . It changes position every 2s.(I used QTimer for it)
      a player shot lots of bullets so my game got lagging so much.
      Is that caused by Timer variables?
      any ideas to solve this issue?
      Thanks alot!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @CongVo
      short:
      A timer fires every interval and executes some code (all executed on the same thread).
      A separate thread supports "concurrent" execution.

      So actually they have nothing in common.

      --- 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
      6
      • C CongVo

        What different between QTimer and QThread?
        When we use QTimer instead of QThread?

        I made a shooting game and i have a class bullet.
        each bullet is a pointer . It changes position every 2s.(I used QTimer for it)
        a player shot lots of bullets so my game got lagging so much.
        Is that caused by Timer variables?
        any ideas to solve this issue?
        Thanks alot!

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

        @CongVo Do you use one timer for each bullet or one for all? Without knowing your implementation it is not possible to say why it is slow with many bullets. But I doubt using more threads will solve it as it looks more like an inefficient implementation. It should be enough to use one timer for all bullets.

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

        1 Reply Last reply
        2
        • D Offline
          D Offline
          DRoscoe
          wrote on last edited by
          #4

          If you want to use threads, I am sure there are elements of your graphics display which are not dependent on the states of the bullets. You could move that to its own thread, so that the updating of the bullet states does not adversely affect your ability to update your graphics. If there is a delay, it should only be on updating the bullets themselves

          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