简体   繁体   English

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

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

I call singleshot in a button press callback, but my timeout slot never gets called, in the debugger my code gets to where i call the singleshot function, but it never gets to the breakpoint in my timeout function.我在按钮按下回调中调用单次触发,但我的超时槽从未被调用,在调试器中我的代码到达我调用单次触发 function 的位置,但它永远不会在我的超时 function 中到达断点。

In the.h:在.h中:

private slots:

void on_snoozeTimeout(Data d);

In the.cpp:在.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
}

The SLOT macro can't accept function parameters the way you are trying to use it. SLOT宏不能以您尝试使用它的方式接受 function 参数。 Use a lambda instead:使用 lambda 代替:

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

Using qt4.8, refactored code to not use parameter使用qt4.8,重构代码不使用参数

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

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