I am programming a application that return a value with QWidget::exec, but seem that i cant close the class properly (i need call Gate::~Gate explicitly for delete the class) and QApplication::exec never exit. Gate is the main window of my aplication
Gate::Gate(List *opciones, QWidget *parent):
QDialog(parent),
ui(new Ui::Gate)
{
ParseOption *ctmp;
int retvalue,i;
ui->setupUi(this);
validUser = false;
setAttribute(Qt::WA_QuitOnClose);
errno = 0; // no se de donde sale el error...
[...code...]
QObject::connect(ui->closeButton,&QAbstractButton::clicked,this,&QDialog::close);
QObject::connect(ui->passwordField,&QLineEdit::textChanged,this,&hellGate::enableopenButton);
QObject::connect(ui->openButton,&QAbstractButton::clicked,this,&hellGate::certificateUser);
QObject::connect(this,&hellGate::validateUser,this,&QDialog::done);
}
when mi program call:
emit validateUser(QDialog::Accepted);
then exit, but Gate when close dont call the destructor, i call this in main but with the flag WA_QuitonClose shall close automaticaly:
int main(int argc, char *argv[])
{
QWidgetList list;
QApplication a(argc, argv);
Gate w(configOptions);
if(w.exec() == QDialog::Accepted) {
w.~Gate();
qDebug("enter");
} else {
qDebug("No enter");
}
list = a.topLevelWidgets();
if(!list.isEmpty()) {
for(int i = 0;i<list.size();i++) {
qDebug("window: %i",list[i]->close());
}
} else {
qDebug("ALL closed");
}
return a.exec();
}
the output is "enter" (and "ALL closed" if i call ~Gate).
i am trying that the program exit from the line "return a.exec()". if i dont destruct Gate explicitly a.topLevelWidget return a list with the a QWidget(i suppose that is Gate). i need call w.exec() because i need that Gate return a value and w.show() is declares as:
void show();
I need call w.exec and that a.exec finish when the windows w(class Gate) close. what am i doing wrong?
PD Sorry if the text is difficult to understand, i dont know English very well.
You create two event loops:
w.exec()
a.exec()
The second event loop is started after you close the dialog, so it will wait indefinitely for a window to be closed.
You can either call show()
for the dialog or not use the QApplication event loop at all:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Gate w(configOptions);
if(w.exec() == QDialog::Accepted)
{
qDebug("enter");
}
else
{
qDebug("No enter");
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.