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
Forum Updated to NodeBB v4.3 + New Features

Dialog does not close correctly

Scheduled Pinned Locked Moved Solved General and Desktop
qdialogclose
3 Posts 2 Posters 879 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 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.

    JonBJ 1 Reply Last reply
    0
    • O OlivierDz

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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 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

        • Login

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