我正在编写一个应用程序,返回一个值与QWidget :: exec,但似乎我无法正确关闭类(我需要调用Gate ::〜门显式删除类)和QApplication :: exec永远不会退出。 门是我aplication的主窗口QApplication不关闭后,我关闭所有QWidget
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);
然后退出,但门在接近不调用析构函数,我称这种现象主要而是用标志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();
}
输出是“输入”(和“如果我打电话给〜门”全部关闭“)。
我正在尝试从程序退出行“return a.exec()”。 如果我没有破坏门显式a.topLevelWidget返回一个QWidget列表(我想这是门)。 我需要调用w.exec(),因为我需要一个门返回值,w.show()是声明:
void show();
我需要调用w.exec和a.exec结束时窗W (班级门)关闭。 我做错了什么?
P.D对不起,如果文字很难理解,我不太懂英语。
是门应用程序的主窗口?你能否澄清为什么你需要明确地调用它的析构函数?通常你调用主窗口的show()然后exec()为应用程序 – demonplus