Results 1 to 3 of 3

Thread: Closing a QDialog

  1. #1
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Closing a QDialog

    Hi,

    I create a widget based on a QDialog and I need to close it when a button inside this widget is pressed. I tried to connect signal/slot on the class constructor, but it doesn't works:

    Qt Code:
    1. LoginUI::LoginUI(QWidget *parent) : QDialog(parent)
    2. {
    3. ...
    4.  
    5. btnOK = new QPushButton("OK");
    6. layDialog->addWidget(btnOK);
    7.  
    8. setLayout(layDialog);
    9. setWindowTitle("Login");
    10. setFixedHeight(180);
    11. setFixedWidth(200);
    12.  
    13. QObject::connect(btnOK, SIGNAL(clicked()), this, SLOT(quit()));
    14. }
    To copy to clipboard, switch view to plain text mode 

    In my main.cpp I call this widget using obj->exec();

    Someone know how to close this dialog and continue the application?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Closing a QDialog

    Change the slot from quit() to close(). QDialog doesn't have "quit()".

  3. The following user says thank you to wysota for this useful post:

    eu.x (10th March 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    New Malden (near London)
    Posts
    32
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Closing a QDialog

    You can use close, but the standard way of closing a dialog called with exec() is to use the slots accept() or reject(). This means that exec() returns a bool (true if accept, false if reject); you can use if( dialog->exec() ) to decide whether to apply whatever changes the user made in the dialog.

Similar Threads

  1. QDialog resize ?
    By allensr in forum Qt Programming
    Replies: 6
    Last Post: 28th October 2007, 22:41
  2. Snap/Dock QDialog to the edge of the screen
    By durbrak in forum Qt Programming
    Replies: 5
    Last Post: 14th December 2006, 04:41
  3. Qdialog as a child widget
    By dave in forum Newbie
    Replies: 12
    Last Post: 14th November 2006, 09:43
  4. Replies: 1
    Last Post: 28th July 2006, 14:10
  5. QDialog in the taskbar (Win32)
    By Arthur in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2006, 16:34

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.