1

is there an updated version of QGIS coding and compilation guide? The current version is clearly outdated. I have been trying to compile the first example, 1_hello_world_qgis_style, though to no avail regrettably. I then adjusted my code as kindly suggested by Tiggey here. I suppose something must be wrong with the include files as I'm still unable to compile.

My platform is Windows/cygwin; I'm using the OSGeo4W64 packages. This is the code I'm using:

//
// QGIS Includes
//
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrendererv2.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectorlayer.h>
#include <qgsmapcanvas.h>
//
// Qt Includes
//
#include <QString>
#include <QApplication>
#include <QWidget>

int main(int argc, char ** argv) 
{
  // Start the Application
  QgsApplication app(argc, argv, true);

  QString myPluginsDir        = "/cygdrive/c/OSGeo4W64/apps/qgis";
  QString myLayerPath         = "/cygdrive/c/Users/defloriv/Documents/qgis/qgis_sample_data/shapefiles";
  QString myLayerBaseName     = "regions";
  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;

mypLayer->setRendererV2(mypRenderer);
if (mypLayer->isValid())
{
    qDebug("Layer is valid");
}
else
{
    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->setExtent(mypLayer->extent());
mypMapCanvas->enableAntiAliasing(true);
mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
mypMapCanvas->freeze(false);
// Set the Map Canvas Layer Set
mypMapCanvas->setLayerSet(myLayerSet);
mypMapCanvas->setVisible(true);
mypMapCanvas->refresh();

return app.exec();
}
  • The guide explains MSYS and Visual Studio builds. Why do you try cygwin? Could you add error messages to your question? – AndreJ Aug 29 '16 at 11:06
0

The first argument of QgsVectorLayer should point directly to a shapefile (not a dir).

I had a lot of trouble to compile C++ code using Qgis API. At QT C++ application using QGIS API you can see the configuration that worked for me.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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