Error LNK2005 when deriving from QVariantMap
-
Hello,
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:
testlibrary.h:
@#ifndef TESTLIBRARY_H
#define TESTLIBRARY_H#include "testlibrary_global.h"
#include <qtcore>class TESTLIBRARY_EXPORT TestLibrary : public QVariantMap
{
public:
TestLibrary();
~TestLibrary();private:
};
#endif // TESTLIBRARY_H
@testlibrary.cpp:
@#include "testlibrary.h"TestLibrary::TestLibrary()
{}
TestLibrary::~TestLibrary()
{}@
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.
testapplication.h:
@#ifndef TESTAPPLICATION_H
#define TESTAPPLICATION_H#include <qtcore>
#include <QtWidgets/QMainWindow>
#include "ui_testapplication.h"class TestApplication : public QMainWindow
{
Q_OBJECTpublic:
TestApplication(QWidget *parent = 0);
~TestApplication();private:
Ui::TestApplicationClass ui;
};#endif // TESTAPPLICATION_H@
testapplication.cpp:
@#include "testapplication.h"
#include <Windows.h>
#include <ActiveQt>
#include "../TestLibrary/TestLibrary.h"TestApplication::TestApplication(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);QAxObject* o;
// propertyBag is a QVariantMap
auto a = o->propertyBag().keys();
}TestApplication::~TestApplication()
{}@
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?