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