Using Arguments with SingleShotTimer
-
Hi,
Is it possible to execute a method which has arguments launched by a single shot timer?
QTimer::singleShot(0, this, SLOT(processMessageBox(arg1, arg2)));
I tried using lamda functions but can't seem to get it to work. If there is a way, can you please provide an example?
Thanks in advance!
-
Hi,
Is it possible to execute a method which has arguments launched by a single shot timer?
QTimer::singleShot(0, this, SLOT(processMessageBox(arg1, arg2)));
I tried using lamda functions but can't seem to get it to work. If there is a way, can you please provide an example?
Thanks in advance!
@leinad sure, lambda is the way to go, assuming
arg1
andarg2
are actual variable namesQTimer::singleShot(0, this, [=]()->void{ //= by-copy capture default processMessageBox(arg1, arg2); });
that said, a single shot time is a bit heavy weight for a 0 timeout, I would recommend QMetaObject::invokeMethod
QMetaObject::invokeMethod(this, [=]()->void{ //= by-copy capture default processMessageBox(arg1, arg2); }, Qt::QueuedConnection // same effect as 0 timeout of a Qtimer );