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. QDialog/QWidget is closing after init
Forum Updated to NodeBB v4.3 + New Features

QDialog/QWidget is closing after init

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 468 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.
  • F Offline
    F Offline
    fem_dev
    wrote on last edited by
    #1

    Here is the main file that creates a App object called w.

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        App w;
        w.show();
        return a.exec();
    }
    

    Here is the App initialization, where I create another window using QDialog. The name of this class is Plot.

    App::App(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::App)
    {
        ui->setupUi(this);
    
        Plot p(this);
        p.setModal(true);
        p.show();
    ...
    }
    

    Why the Plot QDialog window is closing after the show() method?

    F 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Because the variable p is on the stack and is local to the constructor. The show method being not blocking and the constructor ending after the call to show, p is destroyed immediately.

      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
      1
      • F fem_dev

        Here is the main file that creates a App object called w.

        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            App w;
            w.show();
            return a.exec();
        }
        

        Here is the App initialization, where I create another window using QDialog. The name of this class is Plot.

        App::App(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::App)
        {
            ui->setupUi(this);
        
            Plot p(this);
            p.setModal(true);
            p.show();
        ...
        }
        

        Why the Plot QDialog window is closing after the show() method?

        F Offline
        F Offline
        fem_dev
        wrote on last edited by
        #3

        @fem_dev
        I found:

        p.exec();
        
        VRoninV 1 Reply Last reply
        0
        • F fem_dev

          @fem_dev
          I found:

          p.exec();
          
          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @fem_dev

          NOPE! do not block the execution of constructors, App would live in a dangerous limbo if you do that

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Watch out, you are blocking your application until you close your dialog. Is that really what you want ?

            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
            3
            • F Offline
              F Offline
              fem_dev
              wrote on last edited by
              #6

              Sorry guys...you two are right...
              I'm doing this wrong...
              thanks!

              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