tags:

views:

40

answers:

1

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.

+1  A: 

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.

Jake Petroules
Hi Jake, yes, this is exactly what I wish... if you have to write a code most closer to what we discussed, how would you do this?
Leandro Melo de Sales
See the bottom of my post, just below where it says "Side note: you could define an function like:"
Jake Petroules
Jake, this is very far from what I need, this is why I asked about an alternative... thanks anyway.
Leandro Melo de Sales
Sorry I couldn't help. I hope you are able to solve your problem.
Jake Petroules