2015-06-17 48 views
1

我正在编写一个应用程序,返回一个值与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对不起,如果文字很难理解,我不太懂英语。

+0

是门应用程序的主窗口?你能否澄清为什么你需要明确地调用它的析构函数?通常你调用主窗口的show()然后exec()为应用程序 – demonplus

回答

0

创建两个事件循环:

  1. w.exec()
  2. a.exec()

第二个事件循环开始后关闭对话框,所以它会无限期地等待窗口被关闭。

您可以拨打show()的对话框或不使用QApplication的事件循环可言:

int main(int argc, char *argv[]) 
{ 
    QApplication a(argc, argv); 
    Gate w(configOptions); 
    if(w.exec() == QDialog::Accepted) 
    { 
     qDebug("enter"); 
    } 
    else 
    { 
     qDebug("No enter"); 
    } 
} 
+0

我需要QApplication,因为Gate继承自QDialog – JVM

+0

thne现在我强迫a.quit完成,因为我需要w.exec返回值 – JVM

+0

这反应了为什么a.exec不会退出,但没有我能如何正确执行我的程序。 – JVM