PDA

View Full Version : Closing a QDialog



eu.x
10th March 2007, 19:37
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:



LoginUI::LoginUI(QWidget *parent) : QDialog(parent)
{
...

btnOK = new QPushButton("OK");
layDialog->addWidget(btnOK);

setLayout(layDialog);
setWindowTitle("Login");
setFixedHeight(180);
setFixedWidth(200);

QObject::connect(btnOK, SIGNAL(clicked()), this, SLOT(quit()));
}


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

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

wysota
10th March 2007, 19:53
Change the slot from quit() to close(). QDialog doesn't have "quit()".

Matt Smith
12th March 2007, 08:33
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.