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. How to constantly check value of a function while other process are happening

How to constantly check value of a function while other process are happening

Scheduled Pinned Locked Moved Unsolved General and Desktop
lineeditfunctionupdate
7 Posts 5 Posters 817 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.
  • D Offline
    D Offline
    Dean21
    wrote on 17 Jan 2023, 15:40 last edited by
    #1

    So basically I am developing a GUI for mosquitto mqtt. I have a function for subscribing to a topic that I need to be able to constantly check the value of and then update a lineEdit widget. How can I do this if I have other functions of my GUI such as other user inputs etc. From a c++ prospective I would normally just have a while(1) loop, but I have read that it isnt a good idea to use that in qt, as it would stop the rest of the program functioning properly.

    So is there a way I can constantly check the value of a function and update a lineEdit box while also having other stuff in my GUI application.

    FYI: Using Ubuntu, qmake as build and am creating a widget application.

    Anyhelp would be great,
    Thanks in advance,
    Dean

    P 1 Reply Last reply 17 Jan 2023, 18:05
    0
    • M Offline
      M Offline
      mpergand
      wrote on 17 Jan 2023, 16:41 last edited by
      #2

      Hi,

      Use QTimer

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dean21
        wrote on 17 Jan 2023, 16:49 last edited by
        #3

        Hi any particular function that I should look at within the QTimer class?

        C 1 Reply Last reply 17 Jan 2023, 16:56
        0
        • D Dean21
          17 Jan 2023, 16:49

          Hi any particular function that I should look at within the QTimer class?

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 17 Jan 2023, 16:56 last edited by
          #4

          @Dean21 said in How to constantly check value of a function while other process are happening:

          Hi any particular function that I should look at within the QTimer class?

          Simply reading the details of the documentation would help you...

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

          D 1 Reply Last reply 17 Jan 2023, 17:01
          0
          • C Christian Ehrlicher
            17 Jan 2023, 16:56

            @Dean21 said in How to constantly check value of a function while other process are happening:

            Hi any particular function that I should look at within the QTimer class?

            Simply reading the details of the documentation would help you...

            D Offline
            D Offline
            Dean21
            wrote on 17 Jan 2023, 17:01 last edited by
            #5

            @Christian-Ehrlicher yes your right, so just making sure I dont need to use anything like qtconcurrentrun or Qthead or anything along those lines, just something I saw online when researching this

            1 Reply Last reply
            0
            • D Dean21
              17 Jan 2023, 15:40

              So basically I am developing a GUI for mosquitto mqtt. I have a function for subscribing to a topic that I need to be able to constantly check the value of and then update a lineEdit widget. How can I do this if I have other functions of my GUI such as other user inputs etc. From a c++ prospective I would normally just have a while(1) loop, but I have read that it isnt a good idea to use that in qt, as it would stop the rest of the program functioning properly.

              So is there a way I can constantly check the value of a function and update a lineEdit box while also having other stuff in my GUI application.

              FYI: Using Ubuntu, qmake as build and am creating a widget application.

              Anyhelp would be great,
              Thanks in advance,
              Dean

              P Offline
              P Offline
              Pl45m4
              wrote on 17 Jan 2023, 18:05 last edited by Pl45m4
              #6

              @Dean21 said in How to constantly check value of a function while other process are happening:

              So is there a way I can constantly check the value of a function and update a lineEdit box while also having other stuff in my GUI application.

              I would say, it depends on your use-case.
              How you want to check (get the value constantly?!),
              when you want to check (given time interval or on any events?!)
              and what you want to check (only track value changes or even "check", that your value hasn't changed in the last 2h of runtime).

              Instead of a timer where you have an interval, you could start even where the value might be changed from. If your program changes the value, send a signal and handle it as needed.
              If you want to check like every two seconds or so regardless, QTimer is the way to go :)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • J Online
                J Online
                JoeCFD
                wrote on 17 Jan 2023, 18:27 last edited by JoeCFD
                #7

                not sure how you handle your mqtt messages in qt code. Qt has a mqtt module and you may take a look at it.
                I guess you may not need a timer. Instead, you create a signal with info when the message comes and connect that signal with any other qt qwidgets for update.
                No check is needed as well.

                1 Reply Last reply
                0

                7/7

                17 Jan 2023, 18:27

                • Login

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