PDA

View Full Version : call function as Qstring



jcr
29th May 2009, 23:15
Hello,

Is there a way to have:
QString function_name = foo;

call_user_func(function_name, 10);

with somewhere in the codes:

void foo(int);

This feature exists in php

Thanks!

wysota
30th May 2009, 01:35
You can use QScriptEngine::evaluate() to evaluate an invokable function by its name or you can use QMetaObject::invokeMethod() to invoke an invokable method by its name from C++ code directly. Invokable methods are ones that are either slots or have Q_INVOKABLE modifier. Apart from that, what you want is not possible in C++ because it is a compiled binary language as opposed to PHP which is an interpreted textual language.