Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Troubles with the meta system
Qt 6.11 is out! See what's new in the release blog

Troubles with the meta system

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 311 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rock37
    wrote on last edited by
    #1

    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...

    Chris KawaC 1 Reply Last reply
    0
    • R rock37

      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...

      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved