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. Q_DECLARE_TYPEINFO and namespaces - how does it work?

Q_DECLARE_TYPEINFO and namespaces - how does it work?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.8k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      AlekseyOk
      wrote on last edited by
      #2

      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
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          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
          0

          • Login

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