0

我现在对 Java 进行编程已经有一段时间了......现在我进入了 C++ 和 Qt,我对 GUI 线程(EDT 线程)和工作线程有点迷失,我试图让我的应用程序的主窗口只打开当配置窗口关闭时。我不想将用于创建主窗口的代码放在我的配置窗口的 OK 按钮中。我试图使它们成为模态,但主窗口仍然打开......配置完成后我仍然需要查看是否有应用程序更新......所以它就像

编辑:这是我的主要内容:

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();
4

3 回答 3

3

Try something like this:

#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();
}

The idea is that your main window's constructor could accept parameters from the QDialog. In this contrived example I'm just using qDebug() to print the value of the slider in the QDialog when it's closed, not passing it as a parameter, but you get the point.

EDIT: You might also want to "delete" the dialog before creating the main window in order to save memory. In that case you would need to store the parameters for the main window constructor as separate variables before deleting the dialog.

于 2012-04-12T03:26:06.657 回答
3

您必须了解信号和插槽。基本思想是在配置完成时发送一个信号。您将 QMainWindow 放在成员变量中,然后在与 configurationFinished 信号连接的主程序的插槽中调用 mw->show()。

于 2012-04-12T08:41:27.720 回答
1

如果您的 ConfigurationWindow 是 QDialog,您可以将finished(int)信号连接到 MainWindow 的show()插槽(并省略 main 中的 show() 调用)。

于 2012-04-12T09:16:39.853 回答