Important: Please read the Qt Code of Conduct -

Trying to make QT + QGIS working

  • Hi everyone,
    I'm mostly a Java programmer, I worked on C++ many years ago, and knowing this my project manager has asked me to create a little app in QT that can open a shape file, using QGIS.
    But I'm encountering some difficulties.

    I have downloaded the QGIS tutorials of Tim Sutton from GitHub ( and I began working on this: 4_adding_rasters_to_canvas.

    I have downloaded QGIS with all the sources, version 1.8, and QT4 (first I tried QGIS 2.0 and QT5, but I have read that there is no compatibility, so I have tried to reproduce the original envinronment of the tutorials). I have open the project, edited the .pro file to include folders and libraries.
    I have downloaded OSGEO4W64 (I am on Win7) with all the sources.

    I have configured the kit under QT4, using as a compiler Microsoft Visual C++ 10.0 (the only one that doesn't make appear the red error icon in the kits list).

    I have configured CMake with the path to the CMake 2.8 executable.

    When I build the project, I see the following errors:

    @main.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __thiscall QgsApplication::~QgsApplication(void)" (??1QgsApplication@@UAE@XZ) referenced in function _main
    main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall QgsApplication::QgsApplication(int &,char * *,bool,class QString)" (??0QgsApplication@@QAE@AAHPAPAD_NVQString@@@Z) referenced in function _main
    I have triede many things and read threads and docs online to solve this issue, but I want to start again from this point to be sure of what I'm doing.

    My (first for now) question is: I need to compile the QGIS sources under Visual C++ before building the project, because QT can't see the qgis dll?

    Thank for your time.

    Ivan A.

  • Ok, it seems that I've managed to solve the issue: I've recompiled the 1.8 sources with cmake-gui, and linked the libraries in the build folder.
    In this way QT sees the libraries.

    But now I have another issue. There is this code in the tutorial

    @QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);@

    (mypLayer is a QgsRasterLayer*)

    and when building it causes the following error:

    @error: LNK2019: unresolved external symbol "public: class QgsMapLayer * __thiscall QgsMapLayerRegistry::addMapLayer(class QgsMapLayer *,bool,bool)"@

    I have read that the addMapLayer method is deprecated, so I have replaced it with the method addMapLayers (according to Tim Sutton: ).

    So I used:

    @QgsMapLayerRegistry::instance()->addMapLayers(QList<QgsMapLayer*>() << mypLayer);@

    and the error slightly change but doesn't go away...

    @error: LNK2019: unresolved external symbol "public: class QList<class QgsMapLayer *> __thiscall QgsMapLayerRegistry::addMapLayers(class QList<class QgsMapLayer *>,bool,bool)"@

    It's the proper syntax (I found examples on the internet)? There is another way to do this?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    I don't know whether QGIS has several libraries or not. In the first case, are you sure you are linking to all required libraries ?

    Hope it helps

Log in to reply