How to create a thread that permanently gives back values
-
Hello all
I have a function that processes some values and returns them in an array so i can write them into two fields in my UI.QVector<QString> WindowObject::function_a(QVector<QString> values_in){ QVector<QString> values_out; values_out[0] = modify(values_in[0]); values_out[1] = modify(values_in[1]); return values_out; }
in Main:
QVector<QString> get_values; get_values = function_a(QV_values); ui->field_1.set_text(get_values[0]); ui->field_2.set_text(get_values[1]);
Now I want to generate a thread that updates the two fields permanently whe I start the thread and stops updating when I stop the thread. I read about working threads but do not seem to understand it.
Can anybody help me with that?Thomas
-
Hi and welcome to devnet,
How are you modifying this array ?
How long does it take ?
Where does the input come from ? -
@koahnig
HelloI have NO IDEA about slots and signals. I am new to C++ and Qt.
I generated an object representing a window with two lineEdits.Now I want to start a thread that updates those 2 lineEdits with values that are retrieved from a hardware device via USB (the reading off the device already works, but only each time I start it by clicking a button).
Now I want to start a thread that does the updating automatically.
Thomas
-
Probably you need to post some of your code.
When you are using a button and clicking on it is retrieving the information from a usb, you might already use a (signal-)slot functionality.
When you have done it in a Qt way you are probably only required to substitute the button trigger with a QTimer pulling the information on a regular time interval. However,that is a sort of a wild guess based on my experience and the way I would do.
Best is posting the declaration of your class and at the routine doing the pulling of information and display.
Did you use one of Qt templates to start off?