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. Problem with Q_GADGET

Problem with Q_GADGET

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 6.4k 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.
  • F Offline
    F Offline
    Felix
    wrote on last edited by
    #1

    hi
    I have a little problem with Q_GADGET macro. Following example:
    @class A
    {

    };

    class B: public A
    {
    Q_GADGET
    };@

    that code compiles with compiler error "staticMetaObject" is not an element of A

    but wenn i change the code to
    @class A
    {

    };

    class helper
    {
    Q_GADGET
    };

    class B: public helper, public A
    {
    Q_GADGET
    };@

    it compiles with no error. I dont really understand why. Is it important for the moc to have the Q_GADGET class before the other inheritance? Are there other solutions instead of just adding an empty dummy class?

    thanks

    Felix

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      I think that you need Q_GADGET in the base class A is all. I can't recall exactly why but it may be because that is where moc tries to store the static meta object related stuff.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Felix
        wrote on last edited by
        #3

        yah but i cant put it in A, because of the rest of our software. A is a very fundamental class there and i dont want to change it

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          OK, then your second option is to do what you suggested above. It is just like when you make a subclass also inherit form QObject (except that in this case QObject already has the Q_OBJECT macro of course). I don't know of any way around this.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

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

            Q_OBJECT works only for QObject derived classes. This makes QObject the toplevel class in the inheritance hierarchy. As Q_GADGET enables a subset of the meta object system on classes not based on QObject and moc is run anayways, I suspect this holds for those classes too: moc just expects that the base classes are gadgets too.

            Adding the Q_GADGET macro to class A should have no impact on your existing software, as it just adds some extra stuff and does not change your existing code. The only drawback might be a binary incompatibility, due to the fact that the class interface changes.

            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