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. Reflection over class members?
Forum Updated to NodeBB v4.3 + New Features

Reflection over class members?

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

    Hi -

    Using the meta object system, it seems easy to get functions, properties and enums, but not members of a class? Is there any way to iterate over the data members of a class based on QObject?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      The method enumeration only includes signals and slots as well as member functions declared with the Q_INVOKABLE macro.

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

        So I suppose the short answer is "no".

        What would it take to enable the Qt tools to generate information that would do real, first class reflection like one could do in C#? It seems like all the pieces are there - the moc tool would have to collect additional information and the QMetaObject would have to have some more code to let you get at the info.

        Is this ridiculous of me to ask? If not, maybe I should make a feature request? I know that sometimes things that seem "easy" can in actuality be very complicated to do.

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

          [quote author="medvedm" date="1325686847"]So I suppose the short answer is "no".

          What would it take to enable the Qt tools to generate information that would do real, first class reflection like one could do in C#?[/quote]

          Nothing. It would have to be added to the C++ core functionality.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            [quote author="medvedm" date="1325686847"]So I suppose the short answer is "no".[/quote]
            Yes.

            [quote author="medvedm" date="1325686847"]What would it take to enable the Qt tools to generate information that would do real, first class reflection like one could do in C#? It seems like all the pieces are there - the moc tool would have to collect additional information and the QMetaObject would have to have some more code to let you get at the info.[/quote]
            Nothing (besides some minor modifications to <code>moc</code>). Yes.

            [quote author="medvedm" date="1325686847"]Is this ridiculous of me to ask? If not, maybe I should make a feature request? I know that sometimes things that seem "easy" can in actuality be very complicated to do.[/quote]

            If there was such a feature request the quick answer would be: +1.

            At least a single constructor should be included in the meta object, so that every QObject can be created at runtime. Not beeing able to do so as it is right now can be quite tedious.

            In addition, I would prefer full reflection support in Qt over increased meta object size. Having a <code>--reflection</code> / <code>--no-reflection</code> configure switch could be used to enable and disable reflection.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              medvedm
              wrote on last edited by
              #6

              Not sure why Volker dropped the smart-questions bomb. This doesn't seem like an unreasonable question to me. RTTI doesn't do what I am asking for, and I don't think it would have to be added in base C++.

              Qt is already pulling information out about classes I write via moc, so I suppose that is why I'm asking if it is difficult to pull out some more information and make it available to users.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                [quote author="medvedm" date="1325690312"]
                Not sure why Volker dropped the smart-questions bomb. This doesn't seem like an unreasonable question to me. RTTI doesn't do what I am asking for, and I don't think it would have to be added in base C++.
                [/quote]

                The bomb is in the signature, everyone gets it and once I purge it, it's out of every reply :-) you can have your own signature, it's in the "edito profile"/member/profile link.

                [quote author="medvedm" date="1325690312"]

                Qt is already pulling information out about classes I write via moc, so I suppose that is why I'm asking if it is difficult to pull out some more information and make it available to users.[/quote]

                It would work only with QObject based classes, not for plain old classes - and for that be restricted anyways. For accessing members (you mean member methods or member attributes here?) you have the slots (for methods) and the properties (for attributes). Nothing prevents you from declaring every method as a slot, and providing a property for every attribute. I agree that the latter is cumbersome and adds some boilerplate.

                http://www.catb.org/~esr/faqs/smart-questions.html

                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