Error LNK2005 when deriving from QVariantMap
I have a somewhat complicated architecture but I was able to reproduce my problem using the simple setup I am going to explain:
I created a brand new Qt Library whose only class derives from QVariantMap like so:
class TESTLIBRARY_EXPORT TestLibrary : public QVariantMap
#endif // TESTLIBRARY_H
I then created a brand new Qt Application which uses ActiveQt container and ActiveQt server modules and just included my library's header, without even using anything from it.
class TestApplication : public QMainWindow
TestApplication(QWidget *parent = 0);
#endif // TESTAPPLICATION_H@
// propertyBag is a QVariantMap
auto a = o->propertyBag().keys();
When trying to build this, i get
Qt5AxContainerd.lib(qaxbase.obj) : error LNK2005: "public: __thiscall QMap<class QString,class QVariant>::~QMap<class QString,class QVariant>(void)" (??1?$QMap@VQString@@VQVariant@@@@QAE@XZ) already defined in TestLibrary.lib(TestLibrary.dll)
If I just remove the TestLibrary include or the QAxObject usage the solution builds fine.
I'm using Visual Studio 2013 with Qt 5.3.1.
After some brainstorming I came to the conclusion that this probably happens because the compiler is generating the code for the template twice.
So I did a little research I stumbled upon a "post":http://www.mareq.com/2008/10/exporting-non-template-class-inherited.html that suggests exporting the base template class as a workaround but I noticed that none of the container classes (QMap, QList, QHash) are exported.
Is there any solution/workaround for this problem?