UI isn't shown when worker thread runs.
Unsolved
Mobile and Embedded
-
I have one worker thread which parses XML and passing QString parsed data via signal to QLabel slot setText();
I create thread and xmlparse class instances that runs in my MainWindow constructor like this:
MainWindow:MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
startParsing();
}What can cause situation that my UI with label does not appear when application is launched?
-
Hi,
Are you sure that startParsing doesn't block the main thread ?
-
Here is my mainwindow.cpp:
#include "mainwindow.h" #include "ui_mainwindow.h" #include <xmlparser.h> #include <QThread> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); startParsing(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::startParsing() { QThread *xml = new QThread; xmlparser *first = new xmlparser(); first->moveToThread(xml); xml->start(); connect(first, SIGNAL(xmlParsed(QString)), ui->label, SLOT(setText(QString))); }
-
Ok then, are you sure that your label is not just empty rather than not visible ?
Note that you have two memory leaks here.
-
Did you check that xmlparser correctly emits xmlParsed and that the parameter is not empty ?