QState::addTransition method gives error when called by non-pointer type
-
Hello everyone,
I faced with an unexpected error. And I couldn't understand what causes this error.I created one button and want to transmit from phase-1 to phase-2 when button is clicked.
QStateMachine machine; QState phase_1_st; QState phase_2_st; machine.addState(&phase_1_st); machine.addState(&phase_2_st); phase_1_st.addTransition(ui->btn_change, &QPushButton::clicked, phase_2_st); // ERROR: function declaration is not matched
When I used QState variable in pointer type, then problem is resolved.
QStateMachine machine; QState *phase_1_st = new QState(); QState *phase_2_st = new QState(); machine.addState(phase_1_st); machine.addState(phase_2_st); phase_1_st->addTransition(ui->btn_change, &QPushButton::clicked, phase_2_st);
Maybe , it is related with C++ rules, no even Qt.
I would like to learn this mystery :)
Thank you. -
Hi,
Look at the function signature, it takes a pointer to an object and not an object. If you want to keep the object on the stack, you still have to pass its address.
Nothing Qt here, just plain C++.
-
B BosGemiler has marked this topic as solved on