bbbbbbbbb9
bbbbbbbbb9

Reputation: 33

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.

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
}

Upvotes: 0

Views: 1998

Answers (2)

bbbbbbbbb9
bbbbbbbbb9

Reputation: 33

Using qt4.8, refactored code to not use parameter

Upvotes: 0

JarMan
JarMan

Reputation: 8277

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);
});

Upvotes: 1

Related Questions