Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Error LNK2005 when deriving from QVariantMap

Error LNK2005 when deriving from QVariantMap

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fsilva
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fsilva
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved