Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. UI isn't shown when worker thread runs.
QtWS25 Last Chance

UI isn't shown when worker thread runs.

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
user interfaceqt5.5signal & slotqstringconstructor
8 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zola
    wrote on 18 Jan 2016, 10:46 last edited by Zola
    #1

    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?

    J 1 Reply Last reply 18 Jan 2016, 11:06
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Jan 2016, 10:58 last edited by
      #2

      Hi,

      Are you sure that startParsing doesn't block the main thread ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Z 1 Reply Last reply 18 Jan 2016, 11:03
      0
      • S SGaist
        18 Jan 2016, 10:58

        Hi,

        Are you sure that startParsing doesn't block the main thread ?

        Z Offline
        Z Offline
        Zola
        wrote on 18 Jan 2016, 11:03 last edited by
        #3

        @SGaist

        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)));
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 18 Jan 2016, 11:05 last edited by
          #4

          Ok then, are you sure that your label is not just empty rather than not visible ?

          Note that you have two memory leaks here.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Z Zola
            18 Jan 2016, 10:46

            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?

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 18 Jan 2016, 11:06 last edited by
            #5

            @Zola said:

            What can cause situation that my UI with label does not appear when application is launched?

            Did you call MainWindow::show()?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zola
              wrote on 18 Jan 2016, 11:08 last edited by
              #6

              @JKSH @SGaist

              It is shown in main.cpp with:

              MainWindow w;
              w.show();

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 18 Jan 2016, 11:15 last edited by
                #7

                Did you check that xmlparser correctly emits xmlParsed and that the parameter is not empty ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  Zola
                  wrote on 18 Jan 2016, 11:20 last edited by Zola
                  #8

                  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()));
                  
                  1 Reply Last reply
                  0

                  8/8

                  18 Jan 2016, 11:20

                  • Login

                  • Login or register to search.
                  8 out of 8
                  • First post
                    8/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved