UI isn't shown when worker thread runs.
-
wrote on 18 Jan 2016, 10:46 last edited by Zola
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 ?
-
wrote on 18 Jan 2016, 11:03 last edited by
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.
-
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?
@Zola said:
What can cause situation that my UI with label does not appear when application is launched?
Did you call
MainWindow::show()
? -
Did you check that xmlparser correctly emits xmlParsed and that the parameter is not empty ?
-
wrote on 18 Jan 2016, 11:20 last edited by Zola
I solved my problem with not calling parseFunction in its own class constructor but with signals and slots in mainwindow.cpp file:
connect(xml, SIGNAL(started()), first, SLOT(parseFunction()));
8/8