QTimer::singleShot not calling my timeout slot

1.6k Views Asked by At

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.

In the .h:

private slots:

void on_snoozeTimeout(Data d);

In the .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
}
2

There are 2 best solutions below

7
JarMan On

The SLOT macro can't accept function parameters the way you are trying to use it. Use a lambda instead:

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

Using qt4.8, refactored code to not use parameter