繁体   English   中英

QTimer::singleShot 没有调用我的超时槽

[英]QTimer::singleShot not calling my timeout slot

我在按钮按下回调中调用单次触发,但我的超时槽从未被调用,在调试器中我的代码到达我调用单次触发 function 的位置,但它永远不会在我的超时 function 中到达断点。

在.h中:

private slots:

void on_snoozeTimeout(Data d);

在.cpp中:

void MyClass::on_snoozeBtn_clicked()
{                   
   QTimer::singleShot(snoozeTimeoutValue*1000,this,SLOT(on_snoozeTimeout(selectedData)));
}
void MyClass::on_snoozeTimeout(Data d)
{
//not hitting this breakpoint
}

SLOT宏不能以您尝试使用它的方式接受 function 参数。 使用 lambda 代替:

QTimer::singleShot(snoozeTimeoutValue*1000, [this, selectedData](){
    on_snoozeTimeout(selectedData);
});

使用qt4.8,重构代码不使用参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM