Results 1 to 2 of 2

Thread: QDialog, show() works but not close()

  1. #1
    Join Date
    Nov 2016
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDialog, show() works but not close()

    Hi All,

    I am updating some existing code and need to close a qDialog that is opened with show(). But when I try to connect to slots, close(), hide() finished(), etc. I get the error
    error C2039: 'closeEvent' : is not a member of 'QObject'

    Is it possible to close a dialog box without subclassing? Everything is already working and I don't want to re-write the code.

    I have a ui QDialog file created with designer holding multiple widgets. When I press my button it opens a modeless dialog window. All I want to add is that when I press another button it will close the dialog, or hide I don't really care. I can close it using the X button, but want to be able to close it when the user does something in the code that renders the dialog no longer valid,

    The actual code is large, but here is what I am trying to do. Hope it helps.

    Qt Code:
    1. in MyApp.h
    2. #include ui_fullSizeImage.h"
    3. #include "ui_myapp.h"
    4. ...
    5. Ui::MyApp m_ui;
    6. Ui::FullSizeDialog m_fullSizeDialog
    7.  
    8.  
    9. in MyApp.cpp which is a QMainWindow class
    10.  
    11. m_ui.setupUi(this);
    12. m_fullSizeDialog.setupUi(new QDialog(this, Qt::WindowMaximizeButtonHint));
    13.  
    14. // show dialog
    15. connect(m_ui.m_fullScreenButton,
    16. SIGNAL(clicked()),
    17. m_fullSizeDialog.m_dialogWidget->parent(),
    18. SLOT(show()));
    To copy to clipboard, switch view to plain text mode 

    And I want to add

    Qt Code:
    1. // close dialog, wont compile.
    2. connect(m_ui.m_fullScreenCloseButton,
    3. SIGNAL(clicked()),
    4. m_fullSizeDialog.m_dialogWidget->parent(),
    5. SLOT(close()));
    To copy to clipboard, switch view to plain text mode 

    Thanks for your help

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDialog, show() works but not close()

    While this is a seriously weird setup, it should work.

    You could also keep the pointer to the dialog in a member instead of relying that "parent()" on another object returns it.

    Cheers,
    _

Similar Threads

  1. How pushbutton , qthreads works with Qdialog ?
    By narthanl in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2015, 08:37
  2. Replies: 15
    Last Post: 30th October 2012, 07:06
  3. Replies: 9
    Last Post: 25th March 2011, 21:22
  4. How to close a QDialog??
    By Bong.Da.City in forum Newbie
    Replies: 12
    Last Post: 28th August 2010, 10:05
  5. How can I avoid a QDialog close?
    By ricardo in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2009, 19:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.