How to call a method by function pointer?
1 answer
I strongly recommend that you use the normal way, i.e. using QMetaObject::invokeMethod(obj, "function")
. However, if you want, you can use the following string macro:
#define FUNC_NAME(a) (QString(#a).remove(QRegExp("\\((.*)\\)")).trimmed().toLatin1().constData())
//usage
QMetaObject::invokeMethod(obj, FUNC_NAME(function()));
The above macro to string conversion argument then removes the method / function arguments in between (...)
.
0
source to share