【发布时间】:2015-06-17 23:48:22
【问题描述】:
我正在编写一个使用 QWidget::exec 返回值的应用程序,但似乎我无法正确关闭该类(我需要显式调用 Gate::~Gate 以删除该类)并且 QApplication::exec 永远不会退出。 Gate 是我的应用程序的主窗口
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);
}
mi程序调用时:
emit validateUser(QDialog::Accepted);
然后退出,但 Gate 关闭时不调用析构函数,我在 main 中调用它,但带有标志 WA_QuitonClose 将自动关闭:
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();
}
输出是“进入”(如果我调用 ~Gate 则“全部关闭”)。
我正在尝试让程序从“return a.exec()”行退出。 如果我不明确破坏 Gate,a.topLevelWidget 返回一个带有 QWidget 的列表(我想那是 Gate)。 我需要调用 w.exec() 因为我需要 Gate 返回一个值,并且 w.show() 被声明为:
void show();
我需要调用 w.exec 并且当窗口 w(class Gate) 关闭时 a.exec 完成。 我做错了什么?
P.D 对不起,如果文字难以理解,我不太懂英文。
【问题讨论】:
-
Gate 是您应用程序的主窗口吗?您能否澄清一下为什么需要显式调用它的析构函数?通常你调用主窗口的 show(),然后调用 app 的 exec()