QMetaObject::invokeMethod() with arguments
-
wrote on 27 Mar 2019, 17:18 last edited by
Hi,
I would like to use the Functor overload of the invokeMethod() functions since it does compile time checks that the function actually exists. However, how do I pass arguments using this method? Is it possible?
-
Hi,
I would like to use the Functor overload of the invokeMethod() functions since it does compile time checks that the function actually exists. However, how do I pass arguments using this method? Is it possible?
@btse
simply capture them in your lambda function?
You would anyway specify them at the time you call invokeMethodQMetaObject::invokeMethod(obj, [var1,var2]() { ... });
-
@btse
simply capture them in your lambda function?
You would anyway specify them at the time you call invokeMethodQMetaObject::invokeMethod(obj, [var1,var2]() { ... });
wrote on 27 Mar 2019, 17:53 last edited by@raven-worx Thanks. I originally wanted to call a member function, but I guess I can wrap that call with a lambda function.
Note that
dest
lives in a separate thread. Should this be thread safe?connect( lineedit, &QLineEdit::returnPressed, [=]() { QString text = lineedit->text(); QMetaObject::invokeMethod(dest, [=]() { dest->setOutputFilePath(text); }, Qt::QueuedConnection ); } );
-
@raven-worx Thanks. I originally wanted to call a member function, but I guess I can wrap that call with a lambda function.
Note that
dest
lives in a separate thread. Should this be thread safe?connect( lineedit, &QLineEdit::returnPressed, [=]() { QString text = lineedit->text(); QMetaObject::invokeMethod(dest, [=]() { dest->setOutputFilePath(text); }, Qt::QueuedConnection ); } );
@btse said in QMetaObject::invokeMethod() with arguments:
Note that dest lives in a separate thread. Should this be thread safe?
since you explicitly use QueuedConnection yes. You can also use AutoConnection (the default anyway) to let Qt decide.
-
@btse said in QMetaObject::invokeMethod() with arguments:
Note that dest lives in a separate thread. Should this be thread safe?
since you explicitly use QueuedConnection yes. You can also use AutoConnection (the default anyway) to let Qt decide.
wrote on 27 Mar 2019, 18:25 last edited by@raven-worx Yeah I guess the whole lambda capturing is something I still need to get comfortable with, especially when it's used in a multi-thread context.
1/5