Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    General and Desktop
    lineedit function update
    5
    7
    117
    Loading More Posts
    • 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
      Dean21 last edited by

      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

      Pl45m4 1 Reply Last reply Reply Quote 0
      • M
        mpergand last edited by

        Hi,

        Use QTimer

        1 Reply Last reply Reply Quote 0
        • D
          Dean21 last edited by

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

          Christian Ehrlicher 1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion @Dean21 last edited by

            @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 has to stay free or it will die.

            D 1 Reply Last reply Reply Quote 0
            • D
              Dean21 @Christian Ehrlicher last edited by

              @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 Reply Quote 0
              • Pl45m4
                Pl45m4 @Dean21 last edited by Pl45m4

                @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 Reply Quote 0
                • JoeCFD
                  JoeCFD last edited by JoeCFD

                  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 Reply Quote 0
                  • First post
                    Last post