我在我的程序中使用了这个函数:
void delay(QState * state1, int millisecond, QAbstractState * state2)
{
auto timer = new QTimer(state1);
timer->setSingleShot(true);
timer->setInterval(millisecond);
QObject::connect(state1, &QState::entered, timer, static_cast<void (QTimer::*)()>(&QTimer::start));
QObject::connect(state1, &QState::exited, timer, &QTimer::stop);
state1 -> addTransition(timer, SIGNAL(timeout()), state2);
}
我从一个示例中复制粘贴,但我不理解这部分代码:
QObject::connect(state1,..., static_cast<void (QTimer::*)()>(&QTimer::start));
任何人都可以向我解释这段代码是什么?它在程序中是如何工作的?
PS。我试图用这个来改变那个代码,但它没有用:
QTimer *timer = new QTimer(state1);
.
. //same code as before
.
QObject::connect(stato1,&QState::entered,timer,[&] {timer->start();} );
QObject::connect(stato1,&QState::exited, timer,[&] {timer->stop(); } );
stato1 -> addTransition(timer,SIGNAL(timeout()),stato2);