我从MainWindow中的函数调用QWizardPage
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());});
connect(wiz,&QDialog::accepted,[&](){textEdit->setText("Dataset noise filled.\n");});
delete frame->layout(); // delete previous layout
frame->setLayout(ly);
wiz->show();
}
,WizardPage的构造函数看起来像
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);
}
当我接受(并因此关闭)单页向导的对话框时,我收到分段错误。调试器停在connect
指令上,让我相信问题出现了,因为我正在请求两个在编译时未初始化的字段。这种连接也是在运行时进行的,所以我很困惑。有没有人知道发生了什么?
答案 0 :(得分:0)
我弄明白了这个问题。我通过引用捕获lambda函数中的局部变量(wiz
),这导致了未定义的行为,即使变量在执行lambda时仍在范围内。