I like the new syntax for QObject::connect
connect(sender, &Sender::valueChanged, [=](const QString &newValue) {
receiver->updateValue("senderValue", newValue);
});
I want to implement my own method that gets a lambda expression as argument.
In my particular case I want to recreate the Javascript Function setTimeout().
How does the correct syntax look like to have a lambda as argument of my method? I want the lambda not to have any arguments or another return type than void.
void setTimeout(/* SOME_TYPE callback */, int timeout)
{
QTimer *timer = new QTimer(this);
timer->setInterval(timeout);
timer->setSingleShot(true);
connect(timer, &QTimer::timeout, (){
//This lambda should be an argument
});
//connect(timer, &QTimer::timeout, callback);
connect(timer, &QTimer::timeout, timer, &QObject::deleteLater);
timer->start();
}
I can't find the methods defined in QObject. Some are only defined for documentation generation. (#ifdef Q_QDOC
)