QWizard立即打开和关闭

时间:2013-08-11 15:57:18

标签: qt

点击按钮后,我正在使用此功能打开向导:

void Go::runWizardSlot()
{

    QWizard wizard;
    wizard.addPage(::createIntroPage());
    wizard.setWindowTitle("Trivial Wizard");
    wizard.show();

}

当我点击按钮时,会打开对话框,但会立即关闭。这是介绍功能:

QWizardPage *createIntroPage()
 {
     QWizardPage *page = new QWizardPage;
     page->setTitle("Introduction");

     QLabel *label = new QLabel("This wizard will help you register your copy "
                                "of Super Product Two.");
     label->setWordWrap(true);

     QVBoxLayout *layout = new QVBoxLayout;
     layout->addWidget(label);
     page->setLayout(layout);

     return page;
 }

是否有任何功能可以让它保持打开状态?

1 个答案:

答案 0 :(得分:2)

您不能在堆栈上创建向导实例,然后调用show()。显示不会阻止,一旦退出runWizardSlot(),将立即销毁向导实例。

您有两种选择:

  • 调用exec()而不是show()。如果你想要向导模态并且对结果感兴趣,那么工作正常。
  • 使用show()但在堆上创建向导。特别是对于非模态对话框,我更喜欢这个而不是exec()。
相关问题