可以在初始化之前在 QWizard 中请求 field() 吗?
Can field() be requested in a QWizard before initialization?
我正在从 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
指令处停止,这让我相信问题出现了,因为我正在请求两个未在编译时初始化的字段。这个连接确实会在 运行 时间建立,所以我很困惑。有人知道发生了什么事吗?
我想通了。我在 lambda 函数中通过引用捕获局部变量 (wiz
),这导致了未定义的行为,即使在执行 lambda 时该变量仍在范围内。
我正在从 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
指令处停止,这让我相信问题出现了,因为我正在请求两个未在编译时初始化的字段。这个连接确实会在 运行 时间建立,所以我很困惑。有人知道发生了什么事吗?
我想通了。我在 lambda 函数中通过引用捕获局部变量 (wiz
),这导致了未定义的行为,即使在执行 lambda 时该变量仍在范围内。