QT -> 计时器循环,这会导致堆栈溢出吗



以下情况会造成堆栈溢出吗?

// reference elsewhere
this->update();

void devices::Sprinkler::update(){
if(this->_state == devices::Sprinkler::State::ON) {
...
QTimer::singleShot(this->_updateFrequency, this, SLOT(update()));
}
}

我知道如果是

update() {
update(); // stack overflow 
}

但我不完全理解前者的行为。

不,它不会导致堆栈溢出,因为调用不是递归的。QTimer::singleShot()调度一个稍后执行的调用,允许update()在再次调用之前退出并清理其堆栈帧,从而重用堆栈空间。

最新更新