1

I am using this function to open a wizard after clicking a button:

void Go::runWizardSlot()
{

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

}

When I click on a button, this opens the dialog, but closes immediately. Here is the intro function:

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

Is there any function to keep it open?

4

1 回答 1

2

You must not create the wizard instance on the stack and then call show(). Show doesn't block and the wizard instance will be destroyed immediately once runWizardSlot() is exited.

You have two options:

  • Call exec() instead of show(). Works ok if you want the wizard modal and are interested in results.
  • Use show() but create the wizard on the heap. Especially for non-modal dialogs, I'd prefer this over exec().
于 2013-08-11T16:33:39.247 回答