PDA

View Full Version : QLabel Set text not work after A few minutes



lamp
16th November 2012, 18:00
Hi

QLabel Set text not Changed after A few minutes

Code:


int i;
i = `MyNewValue` ;
ui->A_DP->setText(QString::number(i))

qDebug()<<"lable value : "<<ui->A_P->text();


qlable show old fixed value But qDebug print new value ?!

note : SetText Call from QtConcurrent function

Qt ver: 4.8.3 (qws)
OS: debian 2.6.32-5-686

amleto
16th November 2012, 19:14
read my sig.

ChrisW67
17th November 2012, 06:29
Your code, my comments:


int i;
i = `MyNewValue` ; // << Will not compile. i is an int this is not. Backtick quotes are not valid in C++.
ui->A_DP->setText(QString::number(i)) // << Needs ; to compile. Sets A_DP's text

qDebug()<<"lable value : "<<ui->A_P->text(); // << Outputs the text of a different control

As amleto says, if you are going to post code snippets make sure they are at least valid code... and the easiest way to do that is copy and paste from a compiling program.



note : SetText Call from QtConcurrent function

Accessing elements of the (typically private) GUI from a thread other than the main one, and doing so without synchronisation is a Bad Thing.
From the Threads and QObjects docs:

Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread.
Use signal/slot connection or rethink why you want to do this.