I\'ve been searching far and wide for an answer to this but to no avail. My lament is as follows:
I have a ClassA that roughly looks like this:
A few things:
The reason that registering ClassA* isn't working is because your call to construct() is constructing a pointer to a ClassA object, but not an actual object.
It is worthy of noting the following quote from the QMetaType documentation:
Any class or struct that has a public default constructor, a public copy constructor, and a public destructor can be registered.
Take a look at Qt's implementation of qMetaTypeConstructHelper:
template
void *qMetaTypeConstructHelper(const T *t)
{
if (!t)
return new T();
return new T(*static_cast(t));
}
and note their usage of the copy constructor. This being the case, you have two ways around the problem:
1) Provide a copy constructor (which you have done)
2) Provide a specialization of qMetaTypeConstructHelper that doesn't use the copy constructor:
template <>
void *qMetaTypeConstructHelper(const ClassA *)
{
return new ClassA();
}