2012-04-12 181 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()调用)。

相关问题