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. Dialog does not close correctly
QtWS25 Last Chance

Dialog does not close correctly

Scheduled Pinned Locked Moved Solved General and Desktop
qdialogclose
3 Posts 2 Posters 843 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.
  • O Offline
    O Offline
    OlivierDz
    wrote on 16 Oct 2020, 08:04 last edited by
    #1

    Hello,
    I have a dialog box with a custom "Cancel" button. The "Cancel" button clicked event is connected to the QDialog close slot.
    When I click this "Cancel" button, all the widgets of the dialog box disapeared but the dialog itself does not close. When I click the cross at the top-right corner of the dialog, everything is close correctly. I don't know what I'm doing wrong. Here is a part of my code :

        // Open the dialog
        CMyDialog *child = new CMyDialog ();
        child->setAttribute(Qt::WA_DeleteOnClose);
        m_mdiArea->addSubWindow(child);
        child->show();
    
        // Dialog's Constructor 
        CMyDialog ::CMyDialog (QWidget *parent) :
        QDialog(parent),
        ui(new Ui::CMyDialog )
        {
          ui->setupUi(this);
          connect(ui->m_btCancel, SIGNAL(clicked()), this, SLOT(close()));
          ...
        }
    
    
    

    Any help is welcome. Thanks.

    J 1 Reply Last reply 16 Oct 2020, 08:08
    0
    • O OlivierDz
      16 Oct 2020, 08:04

      Hello,
      I have a dialog box with a custom "Cancel" button. The "Cancel" button clicked event is connected to the QDialog close slot.
      When I click this "Cancel" button, all the widgets of the dialog box disapeared but the dialog itself does not close. When I click the cross at the top-right corner of the dialog, everything is close correctly. I don't know what I'm doing wrong. Here is a part of my code :

          // Open the dialog
          CMyDialog *child = new CMyDialog ();
          child->setAttribute(Qt::WA_DeleteOnClose);
          m_mdiArea->addSubWindow(child);
          child->show();
      
          // Dialog's Constructor 
          CMyDialog ::CMyDialog (QWidget *parent) :
          QDialog(parent),
          ui(new Ui::CMyDialog )
          {
            ui->setupUi(this);
            connect(ui->m_btCancel, SIGNAL(clicked()), this, SLOT(close()));
            ...
          }
      
      
      

      Any help is welcome. Thanks.

      J Offline
      J Offline
      JonB
      wrote on 16 Oct 2020, 08:08 last edited by JonB
      #2

      @OlivierDz
      Because you are putting this dialog/window/widget into an QMdiSubWindow you must not close the dialog itself, you must perform such operations on the MDI window which owns/shows it, That is what the the "cross" is doing. You can access the parent MDI subwindow via child->parentWidget() if you need to.

      1 Reply Last reply
      2
      • O Offline
        O Offline
        OlivierDz
        wrote on 16 Oct 2020, 09:02 last edited by
        #3

        @JonB said in Dialog does not close correctly:

        Thanks, it works now.

        I created a custom slot for the Cancel button in my CMyDialog class.
        I this slot a put this->parentWidget()->close().
        This solved the problem.

        1 Reply Last reply
        0

        1/3

        16 Oct 2020, 08:04

        • Login

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