[Qt-interest] Problems with template and function pointer
mario
dodiesis at gmail.com
Thu Nov 4 13:43:05 CET 2010
Hi all,
I have some problem whit a QMap filled of funcion pointers:
My template should have a map of function pointers. Then I should be
able to call a particular function, having a particular string...
But I'm not able to do the "call".
Any help?
This is a simple QT program:
template <typename T> class Module
{
public:
typedef void (T::*memberPtr)( );
typedef QMap<QString, memberPtr> ModuleFunctMap;
Module(){}
void caller( const QString& functName) {
if ( m_mFunctionMap.contains(functName) ) {
memberPtr p = this->m_mFunctionMap[functName];
//now I have the pointer...
//I should call it
//but this is wrong
(this->*p)();
//and this is wrong too
Module<T>* inst = this;
(inst->*p)();
}
}
protected:
ModuleFunctMap m_mFunctionMap;
};
class ModuleTest : public Module<ModuleTest>
{
public:
ModuleTest( ) {
m_mFunctionMap["randomFunctioName"] = &ModuleTest::functionToCall;
}
void functionToCall() {
qDebug() << "YEAH!";
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
ModuleTest test;
test.caller("randomFunctioName");
return a.exec();
}
--
Mario Signorino | www.sgrunt.net
More information about the Qt-interest-old
mailing list