Answer the question
In order to leave comments, you need to log in
How to update label text from static method in QT?
You need to update the UI in a separate thread (pthreads). To do this, you need to pass a callback function (method of the MainWindow class) to pthread_create
. I can't pass a non-static class method as a callback. You can make the method static, but then I don’t know how to access the non-static ui from it. The task seems to be simple, to update the text in the label, but I can’t figure out how to put a callback and update the interface from one function.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
void *MainWindow::status(void *a) {
ui->start->setEnabled(false);
while(true) {
ui->progressBar->setValue(progress); // из статического метода до ui не достучаться
ui->done->setText(QString::number(done));
ui->fail->setText(QString::number(fail));
Sleep(500);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question