2012-04-12 825 views
0

我現在正在編程Java一段時間......現在我進入了C++和Qt,我對GUI線程(EDT線程)和工作線程有點迷失 我試圖讓我的應用程序的主窗口只在配置窗口關閉時打開。 我不想把用於創建主窗口的代碼放在我的配置窗口的確定按鈕中。 我試圖讓他們模態,但主窗口仍然打開..... Afther配置完成我仍然有看看是否有應用程序更新...所以它的東西就像Qt在第一個關閉時打開另一個窗口

編輯:這是我的主:

ConfigurationWindow *cw = new ConfigurationWindow(); 
//if there is no text file - configuration 
cw->show(); 

//**I need to stop here until user fills the configuration 

MainWindow *mw = new MainWindow(); 
ApplicationUpdateThread *t = new ApplicationUpdateThread(); 
//connect app update thread with main window and starts it 
mw->show(); 
+0

您是否特指應用程序的啓動?另外,你在哪裏放置了你發佈的代碼?在main()中? – Anthony 2012-04-12 02:10:59

+0

是的,我的主... sry – fredcrs 2012-04-12 02:43:19

回答

3

嘗試這樣:

#include <QtGui> 

int main(int argc, char *argv[]) 
{ 
    QApplication a(argc, argv); 

    QDialog *dialog = new QDialog; 
    QSlider *slider = new QSlider(dialog); 
    QHBoxLayout *layout = new QHBoxLayout(dialog); 
    layout->addWidget(slider); 
    dialog->setLayout(layout); 
    dialog->exec(); 
    qDebug() << slider->value(); // prints the slider's value when dialog is closed 

    QMainWindow mw; // in your version this could be MainWindow mw(slider->value()); 
    w.show(); 

    return a.exec(); 
} 

的想法是,你的主窗口的構造函數可以接受來自QDialog的參數。在這個人爲的例子中,我只是使用qDebug()在QDialog關閉時打印滑塊的值,而不是將其作爲參數傳遞,但您明白了這一點。

編輯:您可能還想在創建主窗口之前「刪除」對話框以節省內存。在這種情況下,您需要在刪除對話框之前將主窗口構造函數的參數存儲爲單獨的變量。

+0

+1我打算dowvote,然後我意識到這正是OP要求的:) – UmNyobe 2012-04-12 09:21:01

3

您必須學會signals and slots。基本的想法是當你配置完成後你會發送一個信號。將QMainWindow放入一個成員變量中,並在主程序的一個插槽中調用mw-> show(),該插槽與configurationFinished信號相連。

1

如果您的ConfigurationWindow是QDialog,您可以將finished(int)信號連接到MainWindow的show()插槽(並省略main中的show()調用)。

相關問題