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. Use QThread or Timer to constantly update GUI?
Forum Updated to NodeBB v4.3 + New Features

Use QThread or Timer to constantly update GUI?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 913 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.
  • G Offline
    G Offline
    grepAns
    wrote on last edited by
    #1

    I am working on a program in which when ran, the GUI is launched and the GUI needs to be constantly updated based on the values stored in a database (I'm not using any of the QT database tools). For the program, I have multiple functions that create a the connection to the database and get specific values. Those functions store the values in a struct that I made. From there, I have a function that goes through a vector made up of structs that I made, looks at the data in the struct and updates different parts GUI if need be. Currently, all of these functions are running every second, using the same timer. As I've added more functions to the program, I've noticed that the GUI is updating a little more slowly. To fix this delay and avoid more problems in the future (I still have 2 functions to add that need to be ran constantly), I've been reading up on QThreads. After reading through multiple pages, I still haven't found a solid answer on how I should structure this code.

    Should I even be looking into using threads for this program? If not, what is a better way to implement timers for this scenario? If I should be using threads, do I need to subclass them (read a lot of sites arguing for and against)?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You should start by benchmarking these function, you'll see if the times add up "too much".

      Also, how heavy are your GUI updates ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        grepAns
        wrote on last edited by grepAns
        #3

        It's mainly QLabel->setText("value"). But, a few functions are always running to check if any of the data needs to be changed.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Gui operations must be done fro the main thread. So no need to think about it further.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            In that case you should consider the model view paradigm. Fetch your data, update the model(s) if needed and signal what has changed so the view(s) can update their content.

            You can use QDataWidgetMapper to automate that part.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            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