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 close QDialog

How to close QDialog

Scheduled Pinned Locked Moved General and Desktop
qdialogclose dialog
16 Posts 3 Posters 26.3k 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 jsulm

    @gabor53 You did not post code for your dialogs. How are Additem and review implemented?
    Do you have any buttons user can press to close the dialogs?
    Either accept() or reject() must be called.
    And this code should actually show Additem dialog as a modal dialog:

    mAddItem->exec ();
    

    So, at least this dialog is closed, right? Else you cannot proceed with anything else.

    G Offline
    G Offline
    gabor53
    wrote on last edited by
    #7

    @jsulm
    There is a button on the review.ui they can click and close. One of my issue is that is it possible to click on close on review.ui and close both review and additem?

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

      You can call accept() or reject() on additem when you close review.

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

      G 1 Reply Last reply
      0
      • jsulmJ jsulm

        You can call accept() or reject() on additem when you close review.

        G Offline
        G Offline
        gabor53
        wrote on last edited by
        #9

        @jsulm
        Would you please show me how?

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

          First of all it will be quite unexpected behaviour if you would close addItem when user closes review! As user I would expect that if I close review only review is closed. If I understand your code correctly the flow is: add an Item via addItem, from addItem open review to review the item (optional?), then close review, close addItem. So, closing child dialog should not close parent dialog.

          But if you really want to do it this way then just call

          mAddItem->accept();
          

          You would need to pass the pointer to AddItem instance to review.

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

          G 1 Reply Last reply
          0
          • jsulmJ jsulm

            First of all it will be quite unexpected behaviour if you would close addItem when user closes review! As user I would expect that if I close review only review is closed. If I understand your code correctly the flow is: add an Item via addItem, from addItem open review to review the item (optional?), then close review, close addItem. So, closing child dialog should not close parent dialog.

            But if you really want to do it this way then just call

            mAddItem->accept();
            

            You would need to pass the pointer to AddItem instance to review.

            G Offline
            G Offline
            gabor53
            wrote on last edited by
            #11

            @jsulm
            Unfortunately

            mAddItem->accept();
            

            doesn't do anything.
            The surrounding code:

               QMessageBox::StandardButton reply;
               reply = QMessageBox::information(this, "Confirmation","<b><font size='16' color='green'>The Friend is added to the database. Would you like to add more Friends?</font></b>",QMessageBox::Yes | QMessageBox::No);
            
                   Additem *mAdditem = new Additem;
            
               if(reply == QMessageBox::Yes)
               {
                   qDebug() << "Yes was clicked.";
               }
               else
               {
                    mAdditem->accept ();
               }
            
            
            jsulmJ 1 Reply Last reply
            0
            • G gabor53

              @jsulm
              Unfortunately

              mAddItem->accept();
              

              doesn't do anything.
              The surrounding code:

                 QMessageBox::StandardButton reply;
                 reply = QMessageBox::information(this, "Confirmation","<b><font size='16' color='green'>The Friend is added to the database. Would you like to add more Friends?</font></b>",QMessageBox::Yes | QMessageBox::No);
              
                     Additem *mAdditem = new Additem;
              
                 if(reply == QMessageBox::Yes)
                 {
                     qDebug() << "Yes was clicked.";
                 }
                 else
                 {
                      mAdditem->accept ();
                 }
              
              
              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #12

              @gabor53 What is this code supposed to do?
              You create an instance of Additem, but you do not show it - at least you do not call mAdditem->show() or mAdditem->exec()

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

              G 1 Reply Last reply
              0
              • jsulmJ jsulm

                @gabor53 What is this code supposed to do?
                You create an instance of Additem, but you do not show it - at least you do not call mAdditem->show() or mAdditem->exec()

                G Offline
                G Offline
                gabor53
                wrote on last edited by
                #13

                @jsulm
                It supposed to close additem.

                jsulmJ 1 Reply Last reply
                0
                • G gabor53

                  @jsulm
                  It supposed to close additem.

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

                  @gabor53 But you do not show additem - how can it be closed?

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

                  G 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @gabor53 But you do not show additem - how can it be closed?

                    G Offline
                    G Offline
                    gabor53
                    wrote on last edited by
                    #15

                    @jsulm
                    Im trying to close the additem dialog that originally generated the review. So it was called from mainwindow.

                    G 1 Reply Last reply
                    0
                    • G gabor53

                      @jsulm
                      Im trying to close the additem dialog that originally generated the review. So it was called from mainwindow.

                      G Offline
                      G Offline
                      gabor53
                      wrote on last edited by
                      #16

                      I created a new project with 2 dialogs, the sources are mainwindow.cpp and dialog.cpp.
                      The code in dialog.cpp looks like this:

                      #include "dialog.h"
                      #include "ui_dialog.h"
                      
                      Dialog::Dialog(QWidget *parent) :
                          QDialog(parent),
                          ui(new Ui::Dialog)
                      {
                          ui->setupUi(this);
                      }
                      
                      Dialog::~Dialog()
                      {
                          delete ui;
                      }
                      
                      void Dialog::message()
                      {
                          QMessageBox::StandardButton reply;
                             reply = QMessageBox::information(this, "Confirmation","<b><font size='16' color='green'>Do you want to close the 2nd window?</font></b>",QMessageBox::Yes | QMessageBox::No);
                      
                             if(reply == QMessageBox::Yes)
                             {
                                 qDebug() << "Yes was clicked. Close 2nd.";
                                 this->reject();
                             }
                             else
                             {
                                 qDebug()  << "No was clicked. Don't close 2nd.";
                             }
                      }
                      
                      void Dialog::on_pushButton_clicked()
                      {
                          message();
                      }
                      
                      

                      When I click yes, it does what I want, it closes dialog. When I use the same code in my original application, it does nothing (no error message either). What can cause this completely different behavior? Thank you.

                      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