My QLabel
is not updating from slot. I run sender class in separate thread using QObject::moveToThread
:
QThread* serviceThread = new QThread;
service = new ExportService();
connect(service,SIGNAL(stateChanged(Service::ServiceState)),
this,SLOT(statusChanged(Service::ServiceState)));
service->moveToThread(serviceThread);
serviceThread->start();
Service object send states by emiting signal with ServiceState
enum value, this signal is captured by QDialog
slot:
void Dialog::statusChanged(Service::ServiceState s)
{
switch (s) {
case Service::IDLE:
qDebug() << "Idle";
ui->label->setText("Service send response succesfully.");
break;
case Service::REQUESTING:
qDebug() << "Requesting";
ui->label->setText("Requesting response from service...");
break;
case Service::ERROR:
qDebug() << "Error";
ui->label->setText("Error. Cannot get response from service.");
break;
default:
break;
}
}
After operation on the object which emits a signal twice, the first time with value of Service::REQUESTING
and second time with value of Service::IDLE
my QLabel
change text only to "Service send response succesfully.". In the console I can see that qDebug() << "Requesting";
works so the state changed successfully.
After comment out ui->label->setText("Service send response succesfully.");
label has changed to requesting state but after the whole operation was done ie i see "Requesting" in console then "Idle" and after that QLabel has changed.
What should I do if I want to see QLabel changing in realtime?
QLabel
updates too fast and you can't fixed changes. – t3ft3l--iQt::QueuedConnection
In yourconnect()
call for objects moved to another thread. – anonymous