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. Reopening / Rexecuting QDialog is slow
Forum Updated to NodeBB v4.3 + New Features

Reopening / Rexecuting QDialog is slow

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.3k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    BaBene
    wrote on last edited by
    #1

    Hello,

    I noticed a strange behaviour with QDialogs. When reopening, respectively reexecuting (exec()) an instance of a QDialog it takes quite a while for the Dialog to popup (nearly a second i would guess). The first time the QDialog is used it pops up instantaneously.

    Here is a minimal working example:

    mainwindow.h :
    @
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QDialog>

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = 0);
    };

    #endif // MAINWINDOW_H
    @

    mainwindow.cpp :

    @
    #include "mainwindow.h"
    #include <QMenuBar>
    #include <QMenu>
    #include <QAction>
    #include <QDialog>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {
    QMenu *fileMenu = menuBar()->addMenu("File");
    QAction *action = fileMenu->addAction("New File");
    QDialog *dialog = new QDialog(this);

    connect(action, SIGNAL(triggered()), dialog, SLOT(exec&#40;&#41;&#41;);
    

    }
    @

    I also tried open() and show() as the slot, but all show the same behaviour. Is this a known problem / bug or am I doing something wrong here? Maybe it's a problem with my machine? Or are QDialogs
    simply not supposed to be reused / -opened?

    PS: I'm using Qt 5.2.1 with kubuntu 14.04.

    /edit: OK, back home i used the same minimal example i gave in this thread and everything works fine. But my home machine is far more powerful than at my office. Besides that I'm using QT version 5.1.1 at home, so it might be an indication that this behavior is really a bug in version 5.2.1. Maybe someone could confirm this?

    Best regards

    BaBene

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

      No issue with usage like this. Tried in Win and Ubuntu. Did not give delay. Can you try your example with QPushButton and connecting clicked slot with same dialog ? Just checking is it just issue with Menu or some thing as simple pushbutton slot connection as well.

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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BaBene
        wrote on last edited by
        #3

        OK, back to the office i tried what you suggested. I simply used a QPushButton and connected the clicked() signal to the exec() slot of the QDialog, and noticed the same behavior ... So i guess it's an issue with the QDialog itself.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          You can try to measure the delay

          Create a Dialog class and pass QTime to its constructor then before running exec() start timer in MainWindow and print out the elapsed time in showEvent of Dialog class. Something like this

          @
          class Dialog : public QDialog
          {
          Q_OBJECT

          public:
              explicit Dialog(QTime& elapsed, QWidget *parent = 0);
              ~Dialog();
          
          protected:
              void showEvent(QShowEvent *);
          
          private:
              Ui::Dialog *ui;
              QTime& elapsed;
          

          };
          @

          @
          Dialog::Dialog(QTime& elapsed, QWidget *parent)
          : QDialog(parent)
          , ui(new Ui::Dialog)
          , elapsed(elapsed)
          {
          ui->setupUi(this);
          }

          void Dialog::showEvent(QShowEvent *)
          {
          qDebug() << "Elapsed:" << elapsed.elapsed();
          }
          @

          @
          class MainWindow : public QMainWindow
          {
          // all other things
          private slots:
          void openDialog();

          private:
              Dialog* dialog;
              QTime elapsed;
          

          };
          @

          @
          MainWindow::MainWindow(QWidget* parent)
          : QMainWindow(parent)
          {
          dialog = new Dialog(elapsed, this);

          connect(action, SIGNAL(triggered()), this, SLOT(openDialog()));
          

          }

          void MainWindow::openDialog()
          {
          elapsed.restart();
          dialog->exec();
          }

          @

          1 Reply Last reply
          0
          • B Offline
            B Offline
            BaBene
            wrote on last edited by
            #5

            I'll give it a try tomorrow. However, I think that I'll switch to the latest Qt version when I'm back at office, since I switched to the latest version at home, too ;) I hope that this behavior will end when using the latest version (but i might try a few other versions if you want me to). I will keep you updated!

            Thanks so far!

            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