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 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?

    JKSHJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      0
      • SGaistS SGaist

        Hi,

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

        Z Offline
        Z Offline
        Zola
        wrote on 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
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on 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

            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?

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on 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 last edited by
              #6

              @JKSH @SGaist

              It is shown in main.cpp with:

              MainWindow w;
              w.show();

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on 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 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

                  • Login

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