Unsolved value not updated on gui
-
Hi
i am updating a value on GUI in QT in single thread using below code
Label[Index]->setText(time);
this->update();
qApp->processEvents();
qDebug()<<"setting--------------------------------1"<<time<<"index=="<<Index<<">>>>>>>>>>>"<<Label[Index]->text();first time value updated on gui but later it is not updating on gui.
value is set on label correctly, checked using code Label[Index]->text().
but it is not updating on gui.
why it is not updating on GUI, please suggest me what i have to do.
Thanks
Shashi -
Have you set parent to the label as this widget?
here you are updating widget if label has not set parent, update wont reflect to label.
label.setParent(this); -
@Venkatesh-V said in value not updated on gui:
label.setParent(this);
yes i have set label as
Label[i] = new QLabel(this); but its not working
-
@shashi-prasad said in value not updated on gui:
why it is not updating on GUI, please suggest me what i have to do
I would suggest to provide more information as with what you provided it is actually impossible to say why it behaves like this.
Where and when is this code executed? Are you sure it is executed second time at all?
Did you put another QLabel in Label[Index] after first call?
Show your code. -
std::thread commandExecutor(TimeThread);// created thread for updating playback commandExecutor.detach();
Label is created in constructor only before this thread
void Mode::TimeThread()
{
int Index=0;
//time is calculated here in qstring
Label[Index]->setText(time);
this->update();
qApp->processEvents();}
-
@shashi-prasad As I wrote in another thread: do not update UI in other thread than main thread! This is not going to work! UI must be updated in the main thread.