i am new in developpement with C++, i try to realise an application with C++ which can read and display a *.qgs file from Qgis, i tried the code bellow but it doesn't work, it always show me errors "no such file or directory"

#include <QtCore/QString>
#include <QtGui/QApplication>

#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrenderer.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectorlayer.h>
#include <qgsmapcanvas.h>

#include <iostream>

int main(int argc, char *argv[])
QgsApplication app(argc, argv, true);

QString myPluginsDir        = "/usr/lib64/qgis";
QString myLayerPath         = "pathtoashapefile";
QString myLayerBaseName     = "italy";
QString myProviderName      = "ogr";

// Instantiate Provider Registry
QgsProviderRegistry * preg = QgsProviderRegistry::instance(myPluginsDir);

QgsVectorLayer * mypLayer =  new QgsVectorLayer(myLayerPath, myLayerBaseName, myProviderName);

QgsSingleSymbolRendererV2 *mypRenderer = new QgsSingleSymbolRendererV2(QgsSymbolV2::defaultSymbol(mypLayer->geometryType()));

QList <QgsMapCanvasLayer> myLayerSet;

if (mypLayer->isValid())
    qDebug("Layer is valid");
    qDebug("Layer is NOT valid");

// Add the Vector Layer to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);
// Add the Layer to the Layer Set
myLayerSet.append(QgsMapCanvasLayer(mypLayer, TRUE));

// Create the Map Canvas
QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
// Set the Map Canvas Layer Set

return app.exec();
  • Is the error the output of the program, the compiler or the linker?
    – johanvdw
    Apr 12, 2016 at 9:46
  • when i try to compile the programme it show "Qstring no such file or directory" compilation terminated.
    – user71075
    Apr 12, 2016 at 10:16
  • Make sure the needed paths are in your include path. Check -I for g++ or set include paths of your project correctly. This is basic functionality of the compiler.
    – johanvdw
    Apr 12, 2016 at 11:11
  • acctualy i used the code here ( gis.stackexchange.com/questions/112829/… ) i don't know if there is a qgis lib i should install ?!
    – user71075
    Apr 14, 2016 at 8:59
  • You definitely need qgis. The include and lib dirs can be found under the installation, eg C:\Program Files\QGIS Essen\include .
    – johanvdw
    Apr 14, 2016 at 9:20

1 Answer 1


I was at that point a few hours ago; I was following this guide, nice although outdated.

It seems your code are missing some headers. Try adding these:

#include <QString>
#include <QApplication>
#include <QWidget>

Your makefile may also need these modifications (in Windows, check the corresponding configurations in the tools you're using):

INCPATH       = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtXml -I/usr/include/qt4 -I/usr/include/qgis -I. -I.

LIBS          = $(SUBLIBS)  -L/usr/lib/x86_64-linux-gnu -lQtXml -lQtGui -lQtCore -lpthread -lqgis_core 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.