I have a Pointer to a Object that i pass to a lambda function. Because the lambda function is called 1 second after the initial method call, the object is sometimes not valid any more, leading to a segmentation fault.
How can I verify that the item is still valid within the lambda function before using it?
This is how my method using the lambda function looks like:
void myTab::myMethod(QStandardItem *item)
{
QColor blue(0, 0, 128, 20);
QBrush brush(blue);
item->setBackground(brush);
//Restore background after 1000ms
QTimer::singleShot(1000, [item, this]() mutable {
item->setBackground(Qt::transparent); //<-need some advice here
});
}