Q_DECLARE_TYPEINFO and namespaces - how does it work?



  • 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?



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



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



  • 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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.