Solved Dynamc Call for QMetaObject::invokeMethod
-
i want to call Funtions through this function with arguments inside a for giving it index of the forloop as argument
i tried but i couldnt it took e long time
i want to ask about how to use
for (index)
QMetaObject::invokeMethod(object name,function,index)
how could i do that -
The documentation shows how to pass arguments to invokeMethod - or what do you want to achieve?
-
@Christian-Ehrlicher i have tried it
i have enum
and for loop
inside the for loop i want to call QMetaObject::invokeMethod with enum member as function
with index of the loop a argument -
So did you actually read my link? There is an example on how to call invokeMethod with parameters:
QString retVal; QMetaObject::invokeMethod(obj, "compute", Qt::DirectConnection, Q_RETURN_ARG(QString, retVal), Q_ARG(QString, "sqrt"), Q_ARG(int, 42), Q_ARG(double, 9.7));
-
@ThenewQtDev
You said you tried,
can you show is, us what you tried? -
@J-Hilk for(int index = 0 ;index<MyFrame.length();index++)
{int x;
QMetaObject::invokeMethod(this, PresentState,Qt::DirectConnection,Q_RETURN_ARG(int, x),
Q_ARG(int, index),
Q_ARG(QByteArray, MyFrame));}
-
@ThenewQtDev said in Dynamc Call for QMetaObject::invokeMethod:
PresentState
Is incorrect it‘s supposed to be a string or a functionpointer
-
@J-Hilk it is a Qstring
-
@ThenewQtDev
Than I‘m afraid you have to share a bit more code 😉 -
@J-Hilk i have problem when i put the name of the methode as " compute " t works
but when i put it as variable as mymthode it doent work -
@ThenewQtDev
Well that‘s not unexpexted
it‘s expecting a char * not a QString.
Change your variable accordingly and it should work -
@J-Hilk wow thank you it works fine :)