Reputation: 51
Supposing that I have a C++ class X (a Qt qobject, por exemple), with a method, let's say, QMap handleDynMethods(QString alias). if x is a instance of X class, I wish method handleDynMethods(QString alias, QMap parameters) be invoked when I do x->anyAliasName(parameters), producing x->handleDynMethods("anyAliasName", parameters). Is it possible to do something like this in c++ qt?
Thank you, Leandro.
Upvotes: 1
Views: 317
Reputation: 24190
I think you're saying:
"Suppose I have a C++ class X, which inherits QObject, having the following definition:"
class X : QObject
{
public:
QMap handleDynMethods(QString alias, QMap parameters);
};
"If I have a variable x which is an instance of class X..."
X *x = new X();
"Can I invoke the handleDynMethods
method by using the following syntax:"
QMap parameters;
x->anyAliasName(parameters);
"and have it act as if I did:"
QMap parameters;
x->handleDynMethods("anyAliasName", parameters);
If this is what you are asking, then no, this is not possible, sorry.
Side note: you could define an function like:
QMap anyAliasName(QMap parameters)
{
return handleDynMethods("anyAliasName", parameters);
}
but I think you want the "anyAliasName" part to be dynamic, which isn't possible.
Upvotes: 1