Qt 6.11 is out! See what's new in the release
blog
Troubles with the meta system
-
hey folks,
i wanted to try out the meta object system to get all methods of a class ... what's wrong with this code ?
MainWindow w; const QMetaObject *mo = w.metaObject(); QStringList func_list; int m_count = mo->methodCount(); qInfo() << "Number of methods: " << m_count; for(int i=mo->methodOffset(); i<mo->methodCount(); i++){ func_list << QString::fromLatin1(mo->method(i).methodSignature()); } for(int i=0; i<func_list.length(); i++){ auto list = func_list.at(i); foreach(auto &x, func_list){ qInfo() << x; } }i get Number of methods: 40 but no method signatures...
-
hey folks,
i wanted to try out the meta object system to get all methods of a class ... what's wrong with this code ?
MainWindow w; const QMetaObject *mo = w.metaObject(); QStringList func_list; int m_count = mo->methodCount(); qInfo() << "Number of methods: " << m_count; for(int i=mo->methodOffset(); i<mo->methodCount(); i++){ func_list << QString::fromLatin1(mo->method(i).methodSignature()); } for(int i=0; i<func_list.length(); i++){ auto list = func_list.at(i); foreach(auto &x, func_list){ qInfo() << x; } }i get Number of methods: 40 but no method signatures...
@rock37 Because your class apparently has no methods of its own. If you want the inherited methods too start iterating from 0.
methodOffset()is the offset of the non-inherited methods.Also, in the printing part why are you doing it twice? If you get all 40 methods it will print them 40*40 times this way.