2012-07-29 119 views
0

我有一個問題,我打電話給我了QDialog這樣在main():Qt的QDialog的具有隱藏和WA_QuitOnClose

app.setQuitOnLastWindowClosed(true); 
splashWin startWin; 

if(!startWin.exec()) 
{ 
    // Rejected 
    return EXIT_SUCCESS; 
} 

// Accepted, retrieve the data 
startWin.myData... 

而在QDialog的我有以下代碼:

splashWin::splashWin(QWidget *parent) : 
    QDialog(parent), 
    ui(new Ui::splashWin) 
{ 
    ui->setupUi(this); 
    this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); 
    this->setAttribute(Qt::WA_QuitOnClose); 
} 

void splashWin::on_OK_clicked() 
{ 
    // Prepare my data 
    .. 


    accept(); 
} 


void splashWin::show_About_Window() 
{ 
    MyAboutWindow win; 
    setVisible(false); // <- this causes the application to send a "reject" signal!! why?? 
    win.exec(); 
    setVisible(true); 
} 

這是一個非常簡單的代碼,問題是:setVisible(false)或hide()行顯示關於窗口,但一旦該窗口被解除,「拒絕」對話框代碼被髮送,我的應用程序關閉執行

// Rejected 
return EXIT_SUCCESS; 

主線()

這是爲什麼?在我讀的文檔中,hide()不應該返回任何東西。我使用Qt 4.8.2

回答

1

QDialog::setVisible(false)不會中斷自己的事件循環,但你可以顯式調用功能,QWidget::setVisible的基類版本,而不是在爲了避免這種行爲:

void splashWin::show_About_Window() 
{ 
    MyAboutWindow win; 
    QWidget::setVisible(false); 
    win.exec(); 
    setVisible(true); 
} 
+0

謝謝你先生,你解決了我的問題 – 2012-07-29 23:32:29