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. [Solved] QMetaObject::className for derived type
QtWS25 Last Chance

[Solved] QMetaObject::className for derived type

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.9k Views
  • 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.
  • D Offline
    D Offline
    Davita
    wrote on last edited by
    #1

    Hello

    I have the following situation. I have a base class called ABase which derives from QObject and I have several classes which derives from ABase. now I want to get type name of those classes derived from ABase. For this, I tried obj.metaObject()->className(), but it returns the name of ABase, not of the derived class. So my question is, is there a way to get type name of the derived class?
    I know Q_CLASSINFO macro is a solution, I can name all classes, but I want to avoid that.

    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Davita
      wrote on last edited by
      #2

      Allright guys, I found the solution. Just add Q_OBJECT macro in the derived class and that should work :)

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mgran
        wrote on last edited by
        #3

        Thanks for posting your solution Davita :)

        Project Manager - Qt Development Frameworks

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          Hi Davita,

          metaObject->className returns the calls name from the meta object. The meta object is only created, if Q_OBJECT macro is set in the classes header and the MOC compiler created the moc file.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0

          • Login

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