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. Function after setupUi()

Function after setupUi()

Scheduled Pinned Locked Moved Solved General and Desktop
setupfunctionshow
31 Posts 6 Posters 17.0k 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.
  • T Offline
    T Offline
    t0msk
    wrote on 5 Feb 2017, 12:02 last edited by
    #1

    Hello, I would like to show progress bar (in Dialog) during app initialization (connecting to server, checking for updates, etc..).

    Problem is that if I create any logic in Dialog, then UI is displayed after logic in Dialog.

    mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include "QThread"
    #include "QTimer"
    
    void MainWindow::AfterUI() {
    
        //Logic after UI
        QThread::sleep(5);
    }
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QTimer::singleShot(0, this, SLOT(AfterUI()));
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    mainwindow.h:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    public slots:
        void AfterUI();
    
    private:
        Ui::MainWindow *ui;
    };
    
    #endif // MAINWINDOW_H
    

    You can see that in function called AfterUI() I have:

    QThread::sleep(5);
    

    So UI is displayed after sleep function, but I want to display UI before function AfterUI().

    Thank you very much :)

    Student who loves C/C++

    K 1 Reply Last reply 5 Feb 2017, 12:32
    0
    • T t0msk
      5 Feb 2017, 12:02

      Hello, I would like to show progress bar (in Dialog) during app initialization (connecting to server, checking for updates, etc..).

      Problem is that if I create any logic in Dialog, then UI is displayed after logic in Dialog.

      mainwindow.cpp:

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      
      #include "QThread"
      #include "QTimer"
      
      void MainWindow::AfterUI() {
      
          //Logic after UI
          QThread::sleep(5);
      }
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          QTimer::singleShot(0, this, SLOT(AfterUI()));
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      

      mainwindow.h:

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      
      namespace Ui {
      class MainWindow;
      }
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();
      
      public slots:
          void AfterUI();
      
      private:
          Ui::MainWindow *ui;
      };
      
      #endif // MAINWINDOW_H
      

      You can see that in function called AfterUI() I have:

      QThread::sleep(5);
      

      So UI is displayed after sleep function, but I want to display UI before function AfterUI().

      Thank you very much :)

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 5 Feb 2017, 12:32 last edited by kshegunov 2 May 2017, 12:33
      #2

      The UI is displayed when the paint events are processed (which is when the main event loop is spun). So if you block the main event loop (like using QThread::sleep, no events are processed and nothing is displayed. You need to fix your code, so you don't block the event loop.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • T Offline
        T Offline
        t0msk
        wrote on 5 Feb 2017, 12:39 last edited by
        #3

        So how can I create function which is called after all widgets are displayed?

        Student who loves C/C++

        K 1 Reply Last reply 5 Feb 2017, 12:42
        0
        • T t0msk
          5 Feb 2017, 12:39

          So how can I create function which is called after all widgets are displayed?

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 5 Feb 2017, 12:42 last edited by
          #4

          You can't because you're assuming you can know when the last paint event is going to be dispatched and which paint event is "last", which is equivalent to asking a psychic about the future. We are talking event-driven programming here, so just respond to the relevant events. What is it that you want to do in that function anyway?

          Read and abide by the Qt Code of Conduct

          T 1 Reply Last reply 5 Feb 2017, 13:13
          0
          • N Offline
            N Offline
            nestorac
            wrote on 5 Feb 2017, 12:49 last edited by
            #5

            I wonder, would using threads help in this case?

            1 Reply Last reply
            0
            • K kshegunov
              5 Feb 2017, 12:42

              You can't because you're assuming you can know when the last paint event is going to be dispatched and which paint event is "last", which is equivalent to asking a psychic about the future. We are talking event-driven programming here, so just respond to the relevant events. What is it that you want to do in that function anyway?

              T Offline
              T Offline
              t0msk
              wrote on 5 Feb 2017, 13:13 last edited by t0msk 2 May 2017, 14:17
              #6

              @kshegunov said in Function after setupUi():

              You can't because you're assuming you can know when the last paint event is going to be dispatched and which paint event is "last", which is equivalent to asking a psychic about the future. We are talking event-driven programming here, so just respond to the relevant events. What is it that you want to do in that function anyway?

              In function will be connecting to server, getting data from server, parsing data, etc. So I would like to create Dialog with progressbar like loader, which shows you what is program currently doing.

              It is simple loader window, lot of apps use this.

              I am looking for Form_Load function like in C#

              Student who loves C/C++

              M K 2 Replies Last reply 5 Feb 2017, 16:17
              0
              • T t0msk
                5 Feb 2017, 13:13

                @kshegunov said in Function after setupUi():

                You can't because you're assuming you can know when the last paint event is going to be dispatched and which paint event is "last", which is equivalent to asking a psychic about the future. We are talking event-driven programming here, so just respond to the relevant events. What is it that you want to do in that function anyway?

                In function will be connecting to server, getting data from server, parsing data, etc. So I would like to create Dialog with progressbar like loader, which shows you what is program currently doing.

                It is simple loader window, lot of apps use this.

                I am looking for Form_Load function like in C#

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 5 Feb 2017, 16:17 last edited by mrjj 2 May 2017, 16:17
                #7

                @t0msk
                To be sure main window is fully shown and then app will popup a Dialog over it then you can use

                void MainWindow::showEvent( QShowEvent* event ) {
                    QMainWindow::showEvent( event );
                    //your code here
                
                } 
                
                T 1 Reply Last reply 5 Feb 2017, 16:54
                0
                • M mrjj
                  5 Feb 2017, 16:17

                  @t0msk
                  To be sure main window is fully shown and then app will popup a Dialog over it then you can use

                  void MainWindow::showEvent( QShowEvent* event ) {
                      QMainWindow::showEvent( event );
                      //your code here
                  
                  } 
                  
                  T Offline
                  T Offline
                  t0msk
                  wrote on 5 Feb 2017, 16:54 last edited by
                  #8

                  @mrjj

                  It doesnt work

                  I added into mainwindow.cpp:

                  void MainWindow::showEvent( QShowEvent* event ) {
                      QMainWindow::showEvent( event );
                      //your code here
                  
                      QThread::sleep(10);
                  
                      ui->progressBar->setValue(80);
                  }
                  

                  and mainwindow.h:

                  public:
                      explicit MainWindow(QWidget *parent = 0);
                      ~MainWindow();
                      void showEvent(QShowEvent* event);
                  

                  Problem is that, mainwindow shows after 10 seconds.

                  Student who loves C/C++

                  M 1 Reply Last reply 5 Feb 2017, 16:56
                  0
                  • T t0msk
                    5 Feb 2017, 16:54

                    @mrjj

                    It doesnt work

                    I added into mainwindow.cpp:

                    void MainWindow::showEvent( QShowEvent* event ) {
                        QMainWindow::showEvent( event );
                        //your code here
                    
                        QThread::sleep(10);
                    
                        ui->progressBar->setValue(80);
                    }
                    

                    and mainwindow.h:

                    public:
                        explicit MainWindow(QWidget *parent = 0);
                        ~MainWindow();
                        void showEvent(QShowEvent* event);
                    

                    Problem is that, mainwindow shows after 10 seconds.

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 5 Feb 2017, 16:56 last edited by
                    #9

                    @t0msk

                    Hi
                    Do not use QThread::sleep(10);
                    You Freeze whole appfor 10 secs... :)

                    T 1 Reply Last reply 5 Feb 2017, 17:05
                    2
                    • T t0msk
                      5 Feb 2017, 13:13

                      @kshegunov said in Function after setupUi():

                      You can't because you're assuming you can know when the last paint event is going to be dispatched and which paint event is "last", which is equivalent to asking a psychic about the future. We are talking event-driven programming here, so just respond to the relevant events. What is it that you want to do in that function anyway?

                      In function will be connecting to server, getting data from server, parsing data, etc. So I would like to create Dialog with progressbar like loader, which shows you what is program currently doing.

                      It is simple loader window, lot of apps use this.

                      I am looking for Form_Load function like in C#

                      K Offline
                      K Offline
                      kshegunov
                      Moderators
                      wrote on 5 Feb 2017, 16:57 last edited by kshegunov 2 May 2017, 16:58
                      #10

                      @t0msk said in Function after setupUi():

                      I am looking for Form_Load function like in C#

                      I don't know C#, but from a quick search it appears you want to put that code in the constructor after the setupUi call. Nothing is shown until the events are processed, so I don't see why you want to know when the window's shown. Just create your dialog and call show() on it (don't call exec() as it will block the event loop). Connect the signals and slots as appropriate for the case. The data fetching and/or processing you can offload to a worker thread (for example take a look at the concurrent framework).

                      @mrjj said in Function after setupUi():

                      To be sure main window is fully shown and then app will popup a Dialog over it then you can use

                      True, however you are probably going to get multiple show events, so then that part of the code would be executed multiple times. Additionally, you may not have a correct geometry at the time as there's no specific documented order of events; it all will depend on the underlying window manager (although from my experience one gets the show event last at least for Win and X11).

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      1
                      • M mrjj
                        5 Feb 2017, 16:56

                        @t0msk

                        Hi
                        Do not use QThread::sleep(10);
                        You Freeze whole appfor 10 secs... :)

                        T Offline
                        T Offline
                        t0msk
                        wrote on 5 Feb 2017, 17:05 last edited by
                        #11

                        @mrjj said in Function after setupUi():

                        @t0msk

                        Hi
                        Do not use QThread::sleep(10);
                        You Freeze whole appfor 10 secs... :)

                        Is there something else that sleep? Is there for example wait? Because sleep can means that app will freeze, but thread is locked in your app, something like mutex if you want to free thread.

                        @kshegunov

                        My goal is that app will show Dialog where is progress bar and after all data fetching/processing is shown mainwindow and dialog closed.

                        Student who loves C/C++

                        K 1 Reply Last reply 5 Feb 2017, 17:12
                        0
                        • T t0msk
                          5 Feb 2017, 17:05

                          @mrjj said in Function after setupUi():

                          @t0msk

                          Hi
                          Do not use QThread::sleep(10);
                          You Freeze whole appfor 10 secs... :)

                          Is there something else that sleep? Is there for example wait? Because sleep can means that app will freeze, but thread is locked in your app, something like mutex if you want to free thread.

                          @kshegunov

                          My goal is that app will show Dialog where is progress bar and after all data fetching/processing is shown mainwindow and dialog closed.

                          K Offline
                          K Offline
                          kshegunov
                          Moderators
                          wrote on 5 Feb 2017, 17:12 last edited by
                          #12

                          @t0msk said in Function after setupUi():

                          Is there something else that sleep?

                          The point is you should not sleep.

                          My goal is that app will show Dialog where is progress bar and after all data fetching/processing is shown mainwindow and dialog closed.

                          Fine, so why have a main window at all. Also this in no way contradicts what I wrote, just call show() on whatever widget you want to show and connect the signals and slots appropriately.

                          Read and abide by the Qt Code of Conduct

                          1 Reply Last reply
                          1
                          • T Offline
                            T Offline
                            t0msk
                            wrote on 5 Feb 2017, 18:34 last edited by t0msk 2 May 2017, 18:35
                            #13

                            ok, so I created quite hard function for CPU, without sleep:

                            void MainWindow::showEvent( QShowEvent* event ) {
                                QMainWindow::showEvent( event );
                                //your code here
                            
                                ui->progressBar->setValue(20);
                            
                                int i;
                                double result;
                                QString string;
                            
                                for(i = 0;i < 5000000;i++) {
                            
                                    result = ((((i * 1337) / 7) * 3) - 5) % 1937;
                            
                                    string = QString::number(result);
                            
                                    ui->label->setText(string);
                                }
                            
                                ui->progressBar->setValue(80);
                            }
                            

                            It took some seconds, BUT window displayed after math, so I cannot see initial value of progress bar (20). Sorry but I am confused.

                            Student who loves C/C++

                            K 1 Reply Last reply 5 Feb 2017, 20:25
                            1
                            • T t0msk
                              5 Feb 2017, 18:34

                              ok, so I created quite hard function for CPU, without sleep:

                              void MainWindow::showEvent( QShowEvent* event ) {
                                  QMainWindow::showEvent( event );
                                  //your code here
                              
                                  ui->progressBar->setValue(20);
                              
                                  int i;
                                  double result;
                                  QString string;
                              
                                  for(i = 0;i < 5000000;i++) {
                              
                                      result = ((((i * 1337) / 7) * 3) - 5) % 1937;
                              
                                      string = QString::number(result);
                              
                                      ui->label->setText(string);
                                  }
                              
                                  ui->progressBar->setValue(80);
                              }
                              

                              It took some seconds, BUT window displayed after math, so I cannot see initial value of progress bar (20). Sorry but I am confused.

                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 5 Feb 2017, 20:25 last edited by
                              #14

                              Here, however I provide no text here as instruction. You need to read what an event loop is, how it relates to the GUI, what blocking the event loop means and how one can process things without blocking the event loop (multiple topics all available in the documentation).

                              #include <QApplication>
                              #include <QProgressDialog>
                              #include <QTimer>
                              
                              int main(int argc, char ** argv)
                              {
                                  QApplication application(argc, argv);
                              
                                  QTimer timer;
                                  timer.setInterval(100); //< Simulates a long running operation in the background
                                  timer.start();
                              
                                  QProgressDialog dialog(QStringLiteral("Test dialog"), QStringLiteral("Cancel"), 0, 100);
                                  dialog.show();
                              
                                  int counter = 0;
                                  QObject::connect(&timer, &QTimer::timeout, &dialog, [&dialog, &timer, &counter] () -> void {
                                      counter++;
                                      if (counter >= dialog.maximum())  {
                                          timer.stop();
                                          dialog.close();
                                          return;
                                      }
                              
                                      dialog.setValue(counter);
                                  });
                              
                                  QObject::connect(&dialog, &QProgressDialog::canceled, &timer, &QTimer::stop);
                                  QObject::connect(&dialog, &QProgressDialog::canceled, &application, &QApplication::quit);
                              
                                  return QApplication::exec();
                              }
                              

                              Read and abide by the Qt Code of Conduct

                              1 Reply Last reply
                              5
                              • J.HilkJ Offline
                                J.HilkJ Offline
                                J.Hilk
                                Moderators
                                wrote on 6 Feb 2017, 05:50 last edited by
                                #15

                                Hi,

                                I would suggest looking into QSplashScreen it might me the class for your problems.

                                If I understand it correctly, you want to paint the gui, and than initialize the rest of your program displayed by a progressbar.

                                Simplest way to do this would be to call

                                QTimer::singleShot(10,this,&YourClass::SetupWithProgressbar);
                                

                                out of your constructor, right after

                                ui->setupUi(this);
                                

                                but, if your SetupCode is in the same thread as your progressbar, the pbar will most likely not update itself correctly. You'll have to do that manualy.

                                I hope this helps.


                                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                Q: What's that?
                                A: It's blue light.
                                Q: What does it do?
                                A: It turns blue.

                                1 Reply Last reply
                                0
                                • T Offline
                                  T Offline
                                  t0msk
                                  wrote on 6 Feb 2017, 14:11 last edited by
                                  #16

                                  @J.Hilk said in Function after setupUi():

                                  If I understand it correctly, you want to paint the gui, and than initialize the rest of your program displayed by a progressbar.

                                  Exactly!

                                  So my code now looks like this:

                                  #include "mainwindow.h"
                                  #include "ui_mainwindow.h"
                                  
                                  #include "QTimer"
                                  #include "QThread"
                                  
                                  void MainWindow::SetupWithProgressbar() {
                                  
                                      ui->progressBar->setValue(20);
                                  
                                      int i;
                                      double result;
                                      QString string;
                                  
                                      for(i = 0;i < 5000000;i++) {
                                  
                                          result = ((((i * 1337) / 7) * 3) - 5) % 1937;
                                  
                                          string = QString::number(result);
                                  
                                          ui->label->setText(string);
                                      }
                                  
                                      ui->progressBar->setValue(80);
                                  }
                                  
                                  MainWindow::MainWindow(QWidget *parent) :
                                      QMainWindow(parent),
                                      ui(new Ui::MainWindow)
                                  {
                                      ui->setupUi(this);
                                  
                                      QTimer::singleShot(10, this, MainWindow::SetupWithProgressbar());
                                  }
                                  
                                  MainWindow::~MainWindow()
                                  {
                                      delete ui;
                                  }
                                  

                                  But I am getting an error:

                                  error: invalid use of void expression
                                       QTimer::singleShot(10, this, MainWindow::SetupWithProgressbar());
                                                                                          ^
                                  

                                  I think it is correct.

                                  @kshegunov said in Function after setupUi():

                                  Here, however I provide no text here as instruction. You need to read what an event loop is, how it relates to the GUI, what blocking the event loop means and how one can process things without blocking the event loop (multiple topics all available in the documentation).

                                  #include <QApplication>
                                  #include <QProgressDialog>
                                  #include <QTimer>
                                  
                                  int main(int argc, char ** argv)
                                  {
                                      QApplication application(argc, argv);
                                  
                                      QTimer timer;
                                      timer.setInterval(100); //< Simulates a long running operation in the background
                                      timer.start();
                                  
                                      QProgressDialog dialog(QStringLiteral("Test dialog"), QStringLiteral("Cancel"), 0, 100);
                                      dialog.show();
                                  
                                      int counter = 0;
                                      QObject::connect(&timer, &QTimer::timeout, &dialog, [&dialog, &timer, &counter] () -> void {
                                          counter++;
                                          if (counter >= dialog.maximum())  {
                                              timer.stop();
                                              dialog.close();
                                              return;
                                          }
                                  
                                          dialog.setValue(counter);
                                      });
                                  
                                      QObject::connect(&dialog, &QProgressDialog::canceled, &timer, &QTimer::stop);
                                      QObject::connect(&dialog, &QProgressDialog::canceled, &application, &QApplication::quit);
                                  
                                      return QApplication::exec();
                                  }
                                  

                                  Isnt it quite complicated for such simple thing? :/

                                  Student who loves C/C++

                                  J.HilkJ K 2 Replies Last reply 6 Feb 2017, 14:16
                                  0
                                  • T t0msk
                                    6 Feb 2017, 14:11

                                    @J.Hilk said in Function after setupUi():

                                    If I understand it correctly, you want to paint the gui, and than initialize the rest of your program displayed by a progressbar.

                                    Exactly!

                                    So my code now looks like this:

                                    #include "mainwindow.h"
                                    #include "ui_mainwindow.h"
                                    
                                    #include "QTimer"
                                    #include "QThread"
                                    
                                    void MainWindow::SetupWithProgressbar() {
                                    
                                        ui->progressBar->setValue(20);
                                    
                                        int i;
                                        double result;
                                        QString string;
                                    
                                        for(i = 0;i < 5000000;i++) {
                                    
                                            result = ((((i * 1337) / 7) * 3) - 5) % 1937;
                                    
                                            string = QString::number(result);
                                    
                                            ui->label->setText(string);
                                        }
                                    
                                        ui->progressBar->setValue(80);
                                    }
                                    
                                    MainWindow::MainWindow(QWidget *parent) :
                                        QMainWindow(parent),
                                        ui(new Ui::MainWindow)
                                    {
                                        ui->setupUi(this);
                                    
                                        QTimer::singleShot(10, this, MainWindow::SetupWithProgressbar());
                                    }
                                    
                                    MainWindow::~MainWindow()
                                    {
                                        delete ui;
                                    }
                                    

                                    But I am getting an error:

                                    error: invalid use of void expression
                                         QTimer::singleShot(10, this, MainWindow::SetupWithProgressbar());
                                                                                            ^
                                    

                                    I think it is correct.

                                    @kshegunov said in Function after setupUi():

                                    Here, however I provide no text here as instruction. You need to read what an event loop is, how it relates to the GUI, what blocking the event loop means and how one can process things without blocking the event loop (multiple topics all available in the documentation).

                                    #include <QApplication>
                                    #include <QProgressDialog>
                                    #include <QTimer>
                                    
                                    int main(int argc, char ** argv)
                                    {
                                        QApplication application(argc, argv);
                                    
                                        QTimer timer;
                                        timer.setInterval(100); //< Simulates a long running operation in the background
                                        timer.start();
                                    
                                        QProgressDialog dialog(QStringLiteral("Test dialog"), QStringLiteral("Cancel"), 0, 100);
                                        dialog.show();
                                    
                                        int counter = 0;
                                        QObject::connect(&timer, &QTimer::timeout, &dialog, [&dialog, &timer, &counter] () -> void {
                                            counter++;
                                            if (counter >= dialog.maximum())  {
                                                timer.stop();
                                                dialog.close();
                                                return;
                                            }
                                    
                                            dialog.setValue(counter);
                                        });
                                    
                                        QObject::connect(&dialog, &QProgressDialog::canceled, &timer, &QTimer::stop);
                                        QObject::connect(&dialog, &QProgressDialog::canceled, &application, &QApplication::quit);
                                    
                                        return QApplication::exec();
                                    }
                                    

                                    Isnt it quite complicated for such simple thing? :/

                                    J.HilkJ Offline
                                    J.HilkJ Offline
                                    J.Hilk
                                    Moderators
                                    wrote on 6 Feb 2017, 14:16 last edited by
                                    #17

                                    @t0msk said in Function after setupUi():

                                    error: invalid use of void expression
                                         QTimer::singleShot(10, this, MainWindow::SetupWithProgressbar());
                                                                                            ^
                                    

                                    You're using the wrong syntax,

                                    Use ne new one

                                    QTimer::singleShot(10, this, &MainWindow::SetupWithProgressbar);
                                    

                                    or the old one

                                    QTimer::singleShot(10, this, SLOT(SetupWithProgressbar()));
                                    

                                    If you mix them, the compiler will complain :)


                                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                    Q: What's that?
                                    A: It's blue light.
                                    Q: What does it do?
                                    A: It turns blue.

                                    1 Reply Last reply
                                    1
                                    • T Offline
                                      T Offline
                                      t0msk
                                      wrote on 6 Feb 2017, 14:29 last edited by
                                      #18

                                      @J.Hilk said in Function after setupUi():

                                      @t0msk said in Function after setupUi():

                                      error: invalid use of void expression
                                           QTimer::singleShot(10, this, MainWindow::SetupWithProgressbar());
                                                                                              ^
                                      

                                      You're using the wrong syntax,

                                      Use ne new one

                                      QTimer::singleShot(10, this, &MainWindow::SetupWithProgressbar);
                                      

                                      or the old one

                                      QTimer::singleShot(10, this, SLOT(SetupWithProgressbar()));
                                      

                                      If you mix them, the compiler will complain :)

                                      Ah yes there is newer syntax :D So app was compiled successfully, but window displayed without UI (app freezes until math was completed), so i didint see "changing" progress bar.

                                      Student who loves C/C++

                                      M 1 Reply Last reply 6 Feb 2017, 14:35
                                      0
                                      • T t0msk
                                        6 Feb 2017, 14:29

                                        @J.Hilk said in Function after setupUi():

                                        @t0msk said in Function after setupUi():

                                        error: invalid use of void expression
                                             QTimer::singleShot(10, this, MainWindow::SetupWithProgressbar());
                                                                                                ^
                                        

                                        You're using the wrong syntax,

                                        Use ne new one

                                        QTimer::singleShot(10, this, &MainWindow::SetupWithProgressbar);
                                        

                                        or the old one

                                        QTimer::singleShot(10, this, SLOT(SetupWithProgressbar()));
                                        

                                        If you mix them, the compiler will complain :)

                                        Ah yes there is newer syntax :D So app was compiled successfully, but window displayed without UI (app freezes until math was completed), so i didint see "changing" progress bar.

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 6 Feb 2017, 14:35 last edited by mrjj 2 Jun 2017, 14:37
                                        #19

                                        @t0msk
                                        well as long as you keep block the app , it will freeze like that

                                        When you do
                                        for(i = 0;i < 5000000;i++) {

                                        You kill the event loop and hence nothing else work.

                                        An ugly and not recommended way is to call
                                        QCoreApplication::processEvents()
                                        in such loops but its not good design and not needed if you stop blocking it with loops.

                                        T 1 Reply Last reply 6 Feb 2017, 14:40
                                        0
                                        • M mrjj
                                          6 Feb 2017, 14:35

                                          @t0msk
                                          well as long as you keep block the app , it will freeze like that

                                          When you do
                                          for(i = 0;i < 5000000;i++) {

                                          You kill the event loop and hence nothing else work.

                                          An ugly and not recommended way is to call
                                          QCoreApplication::processEvents()
                                          in such loops but its not good design and not needed if you stop blocking it with loops.

                                          T Offline
                                          T Offline
                                          t0msk
                                          wrote on 6 Feb 2017, 14:40 last edited by t0msk 2 Jun 2017, 14:42
                                          #20

                                          @mrjj said in Function after setupUi():

                                          @t0msk
                                          well as long as you keep block the app , it will freeze like that

                                          When you do
                                          for(i = 0;i < 5000000;i++) {

                                          You kill the event loop and hence nothing else work.

                                          An ugly and not recommended way is to call
                                          QCoreApplication::processEvents()
                                          in such loops but its not good design and not needed if you stop blocking it with loops.

                                          I know that I am blocking app, but I dont know how can I create some "logic" (because every logic will occupy CPU) and display it by a progressbar.

                                          Student who loves C/C++

                                          M 1 Reply Last reply 6 Feb 2017, 14:43
                                          0

                                          3/31

                                          5 Feb 2017, 12:39

                                          topic:navigator.unread, 28
                                          • Login

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