[Qt-interest] Problems with template and function pointer
qt at wachtler.de
qt at wachtler.de
Thu Nov 4 14:11:47 CET 2010
p()
On Thu, Nov 04, 2010 at 01:43:05PM +0100, mario wrote:
> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
--
-----------------------------------------------------------------------------
Klaus Wachtler, Breidingstr. 17
29614 Soltau
klaus at wachtler.de
Tel. 05191/70271
0171/4553039
-----------------------------------------------------------------------------
More information about the Qt-interest-old
mailing list