Call QMetaObject :: invokeMethod () with a variable number of parameters

I'm porting FitNesse Slim server at the moment and I'm stuck right now. What I get are these lines:

("id_4", "call", "id", "setNumerator", "20") ("id_5", "call", "id", "setSomethingElse", "10", "8") 

Where "setNumerator" and "setSomethingElse" are the names of the methods that should be called, and "20", "10" and "8" are the arguments that I pass. So, my problem right now, I do not know how to use one invokeMethod call for both methods. My current workaround is as follows:

 //(if instructionLength==5) metaObj->invokeMethod(className, methodName.toAscii().constData(), Qt::DirectConnection, Q_ARG(QVariant, instructions.at(index).at(4))) //(if instructionLength==6) metaObj->invokeMethod(className, methodName.toAscii().constData(), Qt::DirectConnection, Q_RETURN_ARG(QVariant, retArg), Q_ARG(QVariant, instructions.at(index).at(4)), Q_ARG(QVariant, instructions.at(index).at(5))) 

etc.


Therefore, on the one hand, it seems that every invokeMethod call requires very specific information, which makes it difficult with a variable number of arguments. On the other hand, there must be a way, so I do not need to do the same two (or later: ten) times. So the question is, is there any other way to do this with a single call?

+4
source share
1 answer

If you look at the definition of a function, you will see that there is only one version:

 bool QMetaObject::invokeMethod ( QObject * obj, const char * member, QGenericArgument val0 = QGenericArgument( 0 ), QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), QGenericArgument val4 = QGenericArgument(), QGenericArgument val5 = QGenericArgument(), QGenericArgument val6 = QGenericArgument(), QGenericArgument val7 = QGenericArgument(), QGenericArgument val8 = QGenericArgument(), QGenericArgument val9 = QGenericArgument() ) 

In your case, this is what I would do:

 QGenericArgument argumentTable[ 10 ]; ... Fill up your data QMetaObject::invokeMethod( objet, functionName, argumentTable[ 0 ], argumentTable[ 1 ], argumentTable[ 2 ], ... argumentTable[ 9 ] ); 

Arguments that you do not use will be initialized by default, which is the default behavior

+9
source

All Articles