Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to show progress bar before show Dialog.
Forum Updated to NodeBB v4.3 + New Features

How to show progress bar before show Dialog.

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 3.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.
  • jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    You cannot access UI related stuff in a different thread. UI can only be changed in the same thread as QApplication::exec().
    You start TableDialog::loadDataTable in a different thread. This is the first thing to change.
    You can execute heavy calculations in a different thread, but you should not manipulate the UI from that thread. Instead you can use signals and slots to pass data between the two threads (use queued connection).

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    2
    • H Offline
      H Offline
      HAHAHAHAHA
      wrote on last edited by
      #3

      Thank jsulm. Please can you help me make an example of it .

      1 Reply Last reply
      0
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Why do you call TableDialog::loadDataTable() in a different thread?
        All it does is to populate your table, so there is no need to call it in a different thread.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • H Offline
          H Offline
          HAHAHAHAHA
          wrote on last edited by
          #5

          I'm sorry, I understand. Because I dont know to create an other thread run TableDialog::loadDataTable() .

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by dheerendra
            #6

            what is the issue you are facing ? Is it not showing the table ? Or progress bar is not shown ?

            1. One potential issue is about the QCheckBox created in different thread.
            2. You are running load table in different thread and queing the vector list. This may give problem.

            Please do let us know what is exact issue. I can share you the sample which make it work.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            2
            • H Offline
              H Offline
              HAHAHAHAHA
              wrote on last edited by
              #7

              Thank u. Progress bar is shown, but dialog table not show and show error QWidget: "Widgets must be created in the GUI thread."

              jsulmJ 1 Reply Last reply
              0
              • H HAHAHAHAHA

                Thank u. Progress bar is shown, but dialog table not show and show error QWidget: "Widgets must be created in the GUI thread."

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @HAHAHAHAHA As I sad: you should not manipulate UI in a different thread! This is not going to work.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by dheerendra
                  #9

                  Yes. This is the potential problem i was hihlighting. You are calling load function which is executed in different thread. In load function you are creating the QCheckBox which is UI object. So it must be falling. This is nothing do with your progress bar. You should create those UI object in main thread itself. Hope this clarifies.

                  You can make simple change like the following to make it work without threads or QtConcurrent

                  void MyDialog::on_pushButton_clicked() {
                  // FutureWatcher.setFuture(QtConcurrent::run(dialogTable,&TableDialog::loadDataTable,listData));
                  // connect(&FutureWatcher, SIGNAL (finished()), this, SLOT (finishAndShowDialog()));
                  m_progressBar->SetContent("Please waiting....");
                  this->m_progressBar->show();
                  connect(dialogTable, SIGNAL (finished()), this, SLOT (finishAndShowDialog()));
                  dialogTable->loadDataTable(listData);
                  }

                  class TableDialog : public QDialog
                  {
                  Q_OBJECT

                  public:
                  explicit TableDialog(QWidget *parent = 0);
                  ~TableDialog();
                  void loadDataTable(QStringList listData);
                  void test();

                  signals :
                  void finished();
                  ...
                  }

                  void TableDialog::loadDataTable(QStringList listData)
                  {
                  QString checkBoxStyle = "margin-left:25%; margin-right:20%;";
                  for (int i = 0; i < listData.size(); i++)
                  {
                  qDebug() << " Loading the Data ="<<i <<endl;
                  QCheckBox *m_checkbox = new QCheckBox;
                  m_checkbox->setStyleSheet( checkBoxStyle );
                  m_checkbox->setChecked(false);
                  ......
                  }
                  emit finished();
                  }

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  4
                  • H Offline
                    H Offline
                    HAHAHAHAHA
                    wrote on last edited by
                    #10

                    Thanks everyone. :))

                    1 Reply Last reply
                    0
                    • dheerendraD Offline
                      dheerendraD Offline
                      dheerendra
                      Qt Champions 2022
                      wrote on last edited by
                      #11

                      Cool. You can put this qn to SOLVED state. Also upvote if any of our answer helped you fix the issue.

                      Dheerendra
                      @Community Service
                      Certified Qt Specialist
                      http://www.pthinks.com

                      1 Reply Last reply
                      2

                      • Login

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