My project consists of an app that links to two static libraries. Each of the libraries declares Q_DECLARE_METATYPE< QUuid >, in order to use QUuid with QVariant, which leads to a 'redefinition of struct QMetaTypeId< QUuid >' error.
What is the correct way to go about this while keeping the ability to use each library on its own in different projects?
As a workaround you can call the
Q_DECLARE_METATYPEmacro from the implementation files that need it instead of calling it from the header files, or as the documentation suggests, call it from private headers in each library.But because
QUuidstores its content as aQByteArraywhich is already supported byQVariant, you don’t need to useQ_DECLARE_METATYPEto do that (from Qt 4.8 only):or the same thing, but a little less efficiently, with
QString(before Qt 4.8):And since
QVariantwill implicitly convert betweenQStringandQByteArray, you can mixtoStringandtoByteArraywithout any problem.