Qt Forum

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

    Q_DECLARE_TYPEINFO and namespaces - how does it work?

    General and Desktop
    2
    4
    2456
    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.
    • A
      Asperamanca last edited by

      I've used Q_DECLARE_TYPEINFO before on classes that I didn't put into any specific namespace, and never had any problems.

      Now I have a class that should be in a specific namespace, something like this:

      @#include <QTypeInfo>

      namespace MYNAMESPACE
      {

      class MyClass
      {
      public:
      MyClass();

      int data;
      

      };

      } // namespace MYNAMESPACE@

      How do I declare the typeinfo of this class?
      If I put the Q_DECLARE_TYPEINFO inside the namespace brackets, I get the error "error: specialization of 'template<class T> class QTypeInfo' in different namespace"
      If I put the Q_DECLARE_TYPEINFO after the namespace brackets (now declaring the typeinfo for MYNAMESPACE::MyClass), I get the error "error: expected unqualified-id before 'namespace'" in my corresponding cpp file, which looks like this:

      @#include "myclass.h"

      namespace MYNAMESPACE
      {

      MyClass::MyClass()
      {
      }

      } // namespace MYNAMESPACE
      @

      How is this done correctly?

      1 Reply Last reply Reply Quote 0
      • A
        AlekseyOk last edited by

        I've already check these two cases with MSVS2010 and they works fine.
        Do your forget a semicolon sign before @#include <QTypeInfo>@?

        1 Reply Last reply Reply Quote 0
        • A
          Asperamanca last edited by

          I'm testing on Creator with MinGW.
          #include <QTypeInfo> is the first line. Why should there be a semicolon before?

          1 Reply Last reply Reply Quote 0
          • A
            Asperamanca last edited by

            Ok, tested it on VS2010 as well.

            Case 1 (inside namespace bracket) actually works on VS2010.
            Case 2: I did forget the semicolon after the Q_DECLARE_TYPEINFO. This case now works on both compilers. Thanks!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post