Q: Where to place Q_DECLARE_METATYPE statement when using header and source files? I'm using my custom struct within QWizard pages. Let's say a struct (or class) like so:
// foo.h

namespace nm{

struct Foo
{
    Foo();
    void bar();
};

}

I want to be able to registerField with a Q_PROPERTY of type nm::Foo, for example:
// within some QWizardPage class
Q_PROPERTY(nm::Foo foo READ getFoo WRITE setFoo)

I know that in order for me to use it, I have to declare it as Qt metatype: 
Q_DECLARE_METATYPE(nm::Foo)

But I cannot figure out where to correctly place the above statement. I tried to place it at the end of Foo.cpp, but get a compilation error:

path/QtCore/qglobal.h:738: error: static assertion failed: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system. #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)

If I place it at the end of header file while also having a source file, I get: 

/usr/lib/gcc/x86_64-linux-gnu/5/include/stddef.h:149: error: expected constructor, destructor, or type conversion before 'typedef'
   typedef PTRDIFF_TYPE ptrdiff_t;

If I move all the definitions to the Foo.h and use it as a header-only file, then if I place the statement at the end of the file (outside of the namespace), it works. However, my class definitions are kind of long, and I want my class definitions to be placed at the source file.
Is there any way I can use Q_DECLARE_METATYPE while having header and source files for my class and not a header-only file?
EDIT (Solution): I had to fully define my class, i.e., provide public default ctor, copy ctor and dtor. The final code looks like:
// somewhere in Foo.h
#include <QMetaType>

namespace nm{
struct Foo
{
    Foo();
    Foo(const Foo& other);
    ~Foo();

    void bar();
};
} 

Q_DECLARE_METATYPE(nm::Foo)


A: From the documentation (emphasis is mine):

This macro makes the type Type known to QMetaType as long as it provides a public default constructor, a public copy constructor and a public destructor. It is needed to use the type Type as a custom type in QVariant.
This macro requires that Type is a fully defined type at the point where it is used.

That's why the header-only solution works, and AFAIK there is no way but providing a full definition of the type before declaring it as a metatype.
