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()退出并清理其堆栈框架,然后再次调用,从而重用了堆栈空间。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...