QWizardを作成しています。いくつかのQWizardPagesでは、QWizardPageがQWizardでいくつかのプロパティを設定できるように、コンストラクタでコールバックメソッドを提供します。そのようコンボボックス信号をQtのstd ::関数に接続する際の問題
は:にQLineEditに押されたときに入力しBWizardPage1
に
BWizard::BWizard(QWidget *parent, t::WindowFlags): QWizard(parent, f), modelCheckedOut(false), selectedB(0){
// Setup UI and add pages to wizard.
ui.setupUi(this);
// Make callbacks to set data onto Wizard instead of pages.
auto makeLastPage = [this]()
{
int pageId = this->pageIds().last();
this->removePage(pageId);
this->modelCheckedOut = true;
};
auto setB = [this](int b)
{
this->selectedB = b;
};
addPage(new BWizardPage1(setB, this));
addPage(new BWizardPage2(makeLastPage, this));
addPage(new BWizardPage3(this));
}
私はsetB
関数を使用します。私はBWizardPage1
のコンストラクタでこれをバインドします。これは正常に動作します:コンボボックスが変更されたとき、私はmakeLastPage
機能を使用
QObject::connect(ui.searchField, &QLineEdit::returnPressed, this, [&]() {
setB(5);
}
BWizardPage2
に。私はBWizardPage2
のコンストラクタでこれをバインドします。コンボボックスが変更されると、makeLastPage
は空(またはヌル)のように見えます。
QObject::connect(ui.comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [&](int index) {
makeLastPage();
}
誰でも私が間違っていることを教えてもらえますか?私は、参照によってmakeLastPage
をキャプチャすることによりstd::function<void(void)> makeLastPage
とstd::function<void(int)> setB
これは意味があります。しかし、なぜこれは 'BWizardPage1'の' setB'では起こりませんか? – Mads
おそらく、未定義の動作であるためです。定義されていない動作を引き起こすときに起こることの1つは、意図したとおりに実際に動作することです。それ以上のコードなしで伝えるのは難しいです。 –