Can field() be requested in a QWizard before initialization?



  • I am calling a QWizardPage from a function in the MainWindow

    void MainWindow::NoiseFilling()
    {
        QWizard *wiz = new QWizard;
        NoiseFillPage *pg = new NoiseFillPage(&data);
        wiz->addPage(pg);
        wiz->setWindowTitle("Noise Filling");
        wiz->setOption(QWizard::NoBackButtonOnStartPage);
    
        QVBoxLayout *ly = new QVBoxLayout;
        QLabel *pb = new QLabel;
        ly->addWidget(wiz);
        ly->addWidget(pb);
    
        connect(wiz,&QDialog::accepted,[&](){data.NoiseFill(wiz->field("percent").toInt(),wiz->field("factor").toString());});  //problem here
        connect(wiz,&QDialog::accepted,[&](){textEdit->setText("Dataset noise filled.\n");});
        delete frame->layout();   // delete previous layout
        frame->setLayout(ly);
        wiz->show();
    }
    

    and the constructor of the WizardPage looks like that

    NoiseFillPage::NoiseFillPage(DataFrame* df,QWidget* parent)
        : QWizardPage(parent)
    {
        box = new QComboBox;
        lab = new QLabel("Metadata factor");
        lab_2 = new QLabel("% of missing values threshold to fill");
        sb = new QSpinBox;
    
        box->insertItem(0,*(df->className));
        box->insertItems(1,*(df->namesMetaData));
    
        sb->setMaximum(100);
        sb->setMinimum(30);
        sb->setValue(100);
    
        QGridLayout *ly = new QGridLayout;
        ly->addWidget(box,0,0);
        ly->addWidget(lab,0,1);
        ly->addWidget(sb,1,0);
        ly->addWidget(lab_2,1,1);
    
        setLayout(ly);
    
        registerField("factor",box);
        registerField("percent",sb);
    }
    

    I receive a segmentation fault when I accept (and therefore close) the dialog of the one-page wizard. The debugger stops on the connect instruction making me believe that the problem arises because I am requesting two fields which are not initialised in compile-time. It is also true that this connection would be made at run time so I am very confused. After narrowing down the issue it seems that it has to do with the call wiz->field("percent"). Does anybody have an idea of what is going on?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.