I'm new in qt and c++, and I have a problem with threads.
For example, if I have a gui with two QPushButton and one QTextEdit, is it possible to set values to the QTextEdit from a thread (different from the gui main thread) without freezing the gui?
// These are the values that I want to set from the thread
for(i=0;i<100;i++){
qtextedit.setText(i);
}
You shouldn't use your example directly in another thread. However, it isn't too difficult to work things into a good form using signals and slots.
Note: I haven't compiled or tested this. Up and down don't care if the other is running, so if you click both buttons, your text entry may jump all over the place. I obviously left out a lot of stuff. I also added a
sleep( 1 )
to each loop to show that they shouldn't block the main UI.It is possible: either use a signal/slot with a queued connection, or post events to the GUI thread.
Your example is fast enough to not block the GUI though.