下面的操作会造成堆栈溢出吗?
// 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() 在再次调用它之前退出并清理它的堆栈帧,从而重用堆栈空间。
QTimer::singleShot()
update()