Hi,

I am bit late but here are my two cents.

I was researching ways how to compile applications with QGIS. I did not get very far in terms of developing my application, but I think I solved some compiling / linking
problems.

Here is a  small manual

1. All what you need is Os4geoW with development files and VS 2010 Express.
Make sure you install appropriate headers / libs from os4geow web site.

2. Create your CPP fle. Example is attached.

3. Fire Os3GeoW command window (I used windows  cmd, not MSYS) and navigate
  to you folder. Type

qmake -project

This will create .pro file fore you.

4. Now you need to adjust it.  Edit with your favorite editor.

What you need to change:

QT += xml

INCLUDEPATH += . C:/OSGeo4W/apps/qgis/include
DEFINES += CORE_EXPORT= GUI_EXPORT=

LIBS += C:/OSGeo4W/apps/qgis/lib/qgis_analysis.lib C:/OSGeo4W/apps/qgis/lib/qgis_core.lib \
             C:/OSGeo4W/apps/qgis/lib/qgis_gui.lib \
             C:/OSGeo4W/apps/qgis/lib/qgis_networkanalysis.lib

I attached my "pro" file. You can adjust as you need. Better if you use relative paths.


5. Now again use qmake but this time to create VS  project

qmake -tp vc qgis1_clone.pro


6. Switch to VS 2010 Express. Start it and load "qgis1_clone.vcproj"
VS will show conversion wizard, just go through. Now you can compile "release" for your application. So far I got only "release" working but by adjusting libraries it should be possible to get
"debug" as well.


7. You need to change some project setting in VS, apparently qmake did not make them
Here is for release version

- change executable for debug:   release\qgis1_clone.exe
- change debug environment: add PATH=C:\OSGeo4W\bin;C:\OSGeo4W\apps\qgis\bin
   or whatever our path is

Now you can start application within VS (Crtl+F5)

I did not get debug working. I am getting

"The application has failed to start because its side-by-side configuration is in
   correct. Please see the application event log for more detail."

It's something wrong with VS redistributable. Perhaps someone could shed a light
on this.


I hope it helps,

Best Regards
Mikhail









On 11/7/2013 4:25 AM, Jürgen E. Fischer wrote:
Hi Susann,

On Thu, 07. Nov 2013 at 11:53:45 +0100, sschm...@gfi-gis.de wrote:
What the hell ? :-)
It is so nice, There are opening doorways...
I got the sources for the release 2.0.1 - however :-) and cmake builds me
a qgis2.0.1.sln for my VisualStudio. Now compiling my QGis is in progress.
Thank you for guiding me a few steps forward! I'm curious about it if it
is running after this, i will tell you...
You could also use the libraries shipped with OSGeo4W (also in the standalone
installer).   Note that the 32bit version is built with VS2008 and 64bit with
VS2010.


Jürgen


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

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

  QString myPluginsDir = "/home/timlinux/apps/lib/qgis";
  QString myLayerPath = "/home/timlinux/gisdata/brazil/BR_Cidades/";
  QString myLayerBaseName = "Brasil_Cap";
  QString myProviderName = "ogr";
  // Instantiate Provider Registry
  QgsProviderRegistry::instance(myPluginsDir);
  // create a maplayer instance
  QgsVectorLayer * mypLayer =
      new QgsVectorLayer(myLayerPath, myLayerBaseName, myProviderName);
  QgsSingleSymbolRendererV2 *mypRenderer; // = new QgsSingleSymbolRendererV2();
  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();

  // Start the Application Event Loop
  return app.exec();
}

######################################################################
# Automatically generated by qmake (2.01a) Thu Nov 7 09:53:39 2013
######################################################################

TEMPLATE = app
QT += xml
TARGET = 
DEPENDPATH += .
INCLUDEPATH += . C:/OSGeo4W/apps/qgis/include
DEFINES += CORE_EXPORT= GUI_EXPORT=

LIBS += C:/OSGeo4W/apps/qgis/lib/qgis_analysis.lib 
C:/OSGeo4W/apps/qgis/lib/qgis_core.lib \
        C:/OSGeo4W/apps/qgis/lib/qgis_gui.lib \
                C:/OSGeo4W/apps/qgis/lib/qgis_networkanalysis.lib

# Input
SOURCES += qgis1.cpp
_______________________________________________
Qgis-developer mailing list
Qgis-developer@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to