Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt QQ向导立即打开和关闭_Qt - Fatal编程技术网

Qt QQ向导立即打开和关闭

Qt QQ向导立即打开和关闭,qt,Qt,单击按钮后,我正在使用此功能打开向导: void Go::runWizardSlot() { QWizard wizard; wizard.addPage(::createIntroPage()); wizard.setWindowTitle("Trivial Wizard"); wizard.show(); } 当我点击一个按钮时,这会打开对话框,但会立即关闭。以下是介绍函数: QWizardPage *createIntroPage() {

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

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;
 }

是否有任何函数使其保持打开状态?

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

您有两个选择:

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