Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Problem with Q_GADGET

    General and Desktop
    3
    5
    6027
    Loading More Posts
    • 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
      Felix last edited by

      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 Reply Quote 0
      • Z
        ZapB last edited by

        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 Reply Quote 0
        • F
          Felix last edited by

          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 Reply Quote 0
          • Z
            ZapB last edited by

            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 Reply Quote 0
            • G
              goetz last edited by

              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 Reply Quote 0
              • First post
                Last post