How to timeouts a lot of objects
-
Hello,
I receive a lot of events from a class. This is the slot called:@
void caught(int idx);
@When executed it highlights the row number 'idx' on a QTableView.
I want to clear each highlight after, say, 250 ms.
It would be EXTREMELY easy if I can write:@
void caught(int idx)
{
model->highlightRow(idx);
QTimer::singleShot(250, model, SLOT(clearHighlightRow(idx)));
}
@but for some reasons you cannot call a SLOT with parameters :-(
What is the recommended way to achieve the same behavior?
-
Works in all of Qt 5.x as long as you have a compiler that support C++/11 or up.
So, simply write:
@
void caught(int idx)
{
model->highlightRow(idx);
QTimer::singleShot(250, model, idx {model->clearHighlight(idx);});
}
@One thing to take care off: this will cause a crash if model is destructed while there is still a timer running. You can solve that using a QPointer<MyModel> instead of passing a plain pointer to the closure.