0

コードはこちら

void A::fun()
{
    QAction* act = new QAction(this);
    QAction* act2 = new QAction(this);
    connect(act, QAction::triggered, [this, &act2]() {...; act2.setDisable(true);}
                              // crash when &act2 is used to capture the variable
                              // but it is okay using act2 to capture the variable
}

理由は何ですか?ありがとう。

4

1 に答える 1

3

スコープ外になるポインタであるにもかかわらず、参照を取得しているため、ポインタのコピーが機能します。act2

于 2013-02-05T23:38:09.680 に答える