Tutorial 1: Write a simple mapping application using the new QGIS Canvas API

Ok so not everyone wants a full blown GIS desktop application. Sometimes you want to just have a widget inside your application that displays a map while the main goal of the application lies elsewhere. Perhaps a database frontend with a map display?

So lets take a little walk through creating a simple mapping widget. It wont do anything much - just load a shape file and display it in a random colour. But it should give you an idea of the potential for using QGIS as an embedded mapping component. Before I carry on, many thanks to Francis Bolduc who wrote the beginnings of this demo and then came onto IRC today to do some communal debugging of his prototype. Francis kindly agreed to make his work generally available - though I've tweaked it a bit to use shapefiles instead of his original postgis demo.

We start with typical adding the neccessary includes for our app:

//
// QGIS Includes
//
#include <qgsapplication.h>
#include <qgsproviderregistry.h>
#include <qgssinglesymbolrenderer.h>
#include <qgsmaplayerregistry.h>
#include <qgsvectorlayer.h>
#include <qgsmapcanvas.h>
//
// Qt Includes
//
#include <QString>
#include <QApplication>
#include <QWidget>
//
// Std Includes
//
#include <deque.h>
#include <iostream>

We use qgsapplication instead of Qt's QApplication, and get some added benifits of various static methods that can be used to locate library paths and so on.

The provider registry is a singleton that keeps track of vector data provider plugins. It does all the work for you of loading the plugins and so on. The single symbol renderer is the most basic symbology class. It renders points, lines or polygons in a single colour which is chosen at random by default (though you can set it yourself). Every vector layer must have a symbology associated with it.

The map layer registry keeps track of all the layers you are using. The vector layer class inherits from maplayer and extends it to include specialist functionality for vector data.

Finally the mapcanvas is really the nub of the matter. Its the drawable widget that our map will be drawn onto.

Now we can move on to initialising our application....

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";

So now we have a qgsapplication and we have defined some variables. Since I tested this on the mac, I just specified the location of the vector provider plugins as being inside the qgis.app application bundle. It would probaby make more sense in general to keep the qgis libs in one of the standard library search paths on your system (e.g. /usr/lib) but this way will do for now.

The next two variables defined here just point to the shapefile I am going to be using.

The provider name is important - it tells qgis which data provider to use to load the file. Typically you will use 'ogr' or 'postgres'.

Now we can go on to actually create our layer object.

  // Instantiate Provider Registry
  QgsProviderRegistry::instance(myPluginsDir);

First we get teh provider registry initialised. Its a singleton class so we use the static instance call and pass it the provider lib search path. As it initialises it will scan this path for provider libs.

Now we go on to create a layer...

  QgsVectorLayer * mypLayer = 
      new QgsVectorLayer(myLayerPath, myLayerBaseName, myProviderName);
  QgsSingleSymbolRenderer *mypRenderer = new QgsSingleSymbolRenderer(mypLayer->vectorType());
  std::deque<QString> myLayerSet;
  mypLayer->setRenderer(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.push_back(mypLayer->getLayerID());
  mypLayer->setVisible(TRUE);

The code is fairly self explanatory here. We create a layer using the variables we defined earlier. Then we assign the layer a renderer. Next we add it to a layerset (which is used by the mapcanvas to keep track of which layers to render and in what order) and to the maplayer registry. Finally we make sure the layer will be visible.

Now we create a map canvas on to which we can draw the layer.

  // Create the Map Canvas
  QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
  mypMapCanvas->setExtent(mypLayer->extent());
  qDebug(mypMapCanvas->extent().stringRep(2));
  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();

Once again there is nothing particularly tricky here. We create the canvas and then we set its extents to those of our layer. Next we tweak the canvas a bit to draw antialiased vectors. Next we set the background colour, unfreeze the canvas, make it visible and then refresh it.

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

In the last step we simply start the Qt event loop and we are all done. Easy as 1-2-3 eh? in future posts Ill try to do other examples for using raster layers, wms layers and postgres....

When we compile and run it heres what the running app looks like:

Once again many thanks to Francis for prompting this posting.

AttachmentSize
libqgis_minimal_example.jpg11.26 KB

Dear all Please. I am new in

Dear all

Please. I am new in GGis. After reading your tutorial I want to know how to create a layer from
PostGis data.

Best regards.

Help Required!!!

Hi Tim,

i got really inspired after seeing your tutorial on this page. I am presently working on development of a custom GIS application using QGIS APIs. I was going through your code and when i tried to complie it in Borland C++ builder i got the error that

undefined structure CORE_EXPORT

I ahve included all the required header files which i came across from QGIS and Qt. Do i need to include any other file for this definition?

Thanks
Kanwar

Compiling- Having all sorts of difficulties

Hi there All,

I am an absolute newbie to Qt and C++ (well maybe not C++, it has just been a while)

I cannot get this code to compile - I do not even know how to specify the headers locations as mentioned before in this BLOG. Ie I have the svn checkout of the most recent tree, but please can someone tell me how I specify this.

My source is in /home/courtz/dev/cpp/qgis

I need a "hold my hand as I take baby steps" description of how to specify the header files. :)

(this is after even getting qt environment setup, that seemed hard enough) but something isn't right.

Cheers and Regards,
Courtney.

Have you tried following these instructions...

Courtney,
Have you tried following the build instructions located on the WIKI? They contain very detailed instructions for all platforms. If you still have trouble, posting specific issues will help us help you...

http://wiki.qgis.org/qgiswiki/BuildingFromSource

Aaron

Can build cvn source no worries (unstable and 08)

Hi there Aaron

Firstly thanks for the response.

I can compile the "full" qgis without any dramas at all, I have also started writing a plugin that I hope to get working. (for cross referencing a gpx layer to the underlying attributes, for tracking vehicles etc)

So I thought that I would try and compile the tut 6.

Checked out the source - finally managed to get the include dirs sorted, and now I am getting some compile errors. So I thought I would do a make clean which wiped out the .pro file

There was something wrong in there - as it could find everything except qgsconfig.h which seems to only exist when you build the full qgis source.

I think this is because I checked out and was including stuff from the unstable branch - I will try again using the 08 version sources and see if I have a better experience.

******EDIT******

I keep getting this error

[courtz@main tut1]$ make
qmake -o Makefile tut1.pro
WARNING: Failure to find: mainwindow.h
WARNING: Failure to find: mainwindowbase.ui
make: *** No rule to make target `mainwindowbase.ui', needed by `mainwindowbase.h'. Stop.
[courtz@main tut1]$ qmake
WARNING: Failure to find: mainwindow.h
WARNING: Failure to find: mainwindowbase.ui

I obviously do not have all the files from this tutorial - where can I get them???

This aside - a step by step would be nice to take me back to basics with tut 1 and successfully getting this to work.compile. I jumped too far ahead of myself.

I would prefer to write the app from scratch and use only the components I need to get the functionality that I am after.

But please start me off in the right direction.

Cheers and Regards,
Courtney.

Displaying vector layer

Hi Tim,

I'm using your tutorial to learn QGIS and have a question regarding the qgsvectorlayer class. In your tutorial, you call the setVisible(TRUE) function of the qgsvectorlayer class (mypLayer->setVisible(TRUE)), however, in the latest QGIS release 0.9.0, the qgsvectorlayer class doesn't have a setVisible() function. Do you know which other function I can use that will cause the same behavior?? Thanks.

Regards,
Bill

Re: Disaplying a vector layer

Hi

Indeed the API has changed a little and I probably need to go through and update all my tutorials. For now I can point you to a working example in my openModeller Desktop code:

OmgMainWindow source

If you look at around line 1479 in that file you will see I start by creating a vector layer, set some symbolisation properties for it and then at around lines

 1565             QgsMapLayerRegistry::instance()->addMapLayer(mypVectorLayer, TRUE);
 1566             myList.append(QgsMapCanvasLayer(mypVectorLayer, TRUE)); //bool visibility

The layer is added to the registry and also appended to a QList.

Finally this line adds my layers list to the canvas:

1673   mpMapCanvas->setLayerSet(myList);

Hope that helps!

Regards

Tim

Cannot compile using tutorial code

Hi Tim,

Im using your tutorial code to learn QGIS with 0.9.1, now when i try to compile a very simplified version of the code i receive the following errors:

In file included from main.cpp:28:
/usr/include/qgis/qgsapplication.h:21: error: function definition does not declare parameters
main.cpp: In function ‘int main(int, char**)’:
main.cpp:33: error: ‘QgsApplication’ was not declared in this scope
main.cpp:33: error: expected `;' before ‘app’
main.cpp:37: error: ‘app’ was not declared in this scope
main.cpp: At global scope:
main.cpp:30: warning: unused parameter ‘argc’
main.cpp:30: warning: unused parameter ‘argv’
make: *** [main.o] Error 1

is this error due to the version im using or the .pro file paths as it seems to be finding the qgsapplication header file?

thanks in advance
nathan.

Update .pro file

Just to answer my own question:

you need to include the following to the .pro file definitions:

DEFINES += QGISPLUGINDIR=$${QGISPLUGINDIR} CORE_EXPORT= GUI_EXPORT=

the CORE_EXPORT is used with windows and left blank with linux in the QGIS CCMake file.

therefore it is just required to be declared and left a null for linux compilations

Re: Displaying a vector layer

Thanks. That helps a lot.

Regards,
Bill

How to Compile this application on Linux

hi Tim
I am new to GIS world, I want to know how to compile this application on Linux.
In my system QT-4.2.3 and QGIS 0.8 is installed.
While compiling it like we compile qt application it was showing all our QGIS header file as no such file or directory due to which all functions related to QGIS was showing error.............

This is the error i am getting.........

g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.2.3/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.2.3/include/QtCore -I/usr/local/Trolltech/Qt-4.2.3/include/QtCore -I/usr/local/Trolltech/Qt-4.2.3/include/QtGui -I/usr/local/Trolltech/Qt-4.2.3/include/QtGui -I/usr/local/Trolltech/Qt-4.2.3/include -I. -I. -I. -o main.o main.cpp
main.cpp:4:28: error: qgsapplication.h: No such file or directory
main.cpp:5:33: error: qgsproviderregistry.h: No such file or directory
main.cpp:6:37: error: qgssinglesymbolrenderer.h: No such file or directory
main.cpp:7:33: error: qgsmaplayerregistry.h: No such file or directory
main.cpp:8:28: error: qgsvectorlayer.h: No such file or directory
main.cpp:9:26: error: qgsmapcanvas.h: No such file or directory
In file included from /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/backward/deque.h:59,
from main.cpp:19:
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../../include/c++/4.1.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.
main.cpp: In function ‘int main(int, char**)’:
main.cpp:25: error: ‘QgsApplication’ was not declared in this scope
main.cpp:25: error: expected `;' before ‘app’
main.cpp:33: error: ‘QgsProviderRegistry’ has not been declared
main.cpp:35: error: ‘QgsVectorLayer’ was not declared in this scope
main.cpp:35: error: ‘mypLayer’ was not declared in this scope
main.cpp:36: error: expected type-specifier before ‘QgsVectorLayer’
main.cpp:36: error: expected `;' before ‘QgsVectorLayer’
main.cpp:37: error: ‘QgsSingleSymbolRenderer’ was not declared in this scope
main.cpp:37: error: ‘mypRenderer’ was not declared in this scope
main.cpp:37: error: expected type-specifier before ‘QgsSingleSymbolRenderer’
main.cpp:37: error: expected `;' before ‘QgsSingleSymbolRenderer’
main.cpp:50: error: ‘QgsMapLayerRegistry’ has not been declared
main.cpp:56: error: ‘QgsMapCanvas’ was not declared in this scope
main.cpp:56: error: ‘mypMapCanvas’ was not declared in this scope
main.cpp:56: error: expected type-specifier before ‘QgsMapCanvas’
main.cpp:56: error: expected `;' before ‘QgsMapCanvas’
main.cpp:68: error: ‘app’ was not declared in this scope
main.cpp: At global scope:
main.cpp:22: warning: unused parameter ‘argc’
main.cpp:22: warning: unused parameter ‘argv’
make: *** [main.o] Error 1

Re: How to compile this application on linux

Hi

You need to edit the .pro file and make sure it is pointing to the correct location for your QGIS headers.

Regards

Tim

Can you use embedded mapping components with Qt3

Hi Tim,

This looks perfect for what i need, do you know if the GIS functionality used above works with older versions of QGIS and can intergrate with their corresponding Qt3 Designer, as my working environment OS is required to be SUSE enterprise 10, which has no Qt4 development packages.

cheers,

nlev

Re: Can you use embedded mapping components with Qt3

I believe we switched to Qt4 from version 0.8.0 so you could probably achieve similar results using one of the QGIS 0.7 releases.

Regards

Tim

How to Compile this application on Linux and/or Windows ?

I like this simple map and i want to build the same upon linux and/or windows plate forme, my aime is to build a trackning map for vehiculs, so i need to do periodicaly refrechement for layers, to see vehiculs moving on the map.

Thank you

Nice example

I like this tutorial, many thanks to Francis for creating it and also to Tim for adding more comments.

I just miss some cleanup here - before exiting you should remove layers from registry (AFAIK it's not done automatically):

QgsMapLayerRegistry::instance()->removeAllMapLayers();

Also QgsMapCanvas doesn't get deleted, probably easier way is to use it as a local variable, e.g.

QgsMapCanvas myMapCanvas(0, 0);

Application cleanup

Hi

Yes normally one should clean up afterwards, but in this case where the application has no classes only a simple main() method, removing layers before the main Qt event loop is called will probably cause nothing to be displayed? In the case where it implemented in a class with a destructor it would make more sense. I suppose I could do this after the exec call and will update the example accordingly.

I agree it is better to allocate objects on the stack rather than the heap where possible so memory management is automatic.

Regards

Tim

Yes, cleaning after the exec

Yes, cleaning after the exec call should do it.

missing files in #include

Great job!

However, it seems the < and > characters around included file names are stripped,
so Qt and Std includes are not visible.

missing files in #include

Hi

Oops I thought I had that sorted but obviously missed a couple...should be all hunky dory now. Thanks for pointing that out!

Regards

Tim

how to compile this application

Hello,
could somebody tell me how to compile this application.
Thanks in advance.
cheers
satya

When I tried to compile this

When I tried to compile this application, it always showed fatal error "can`t find Qlist". Acctualy I have installed QT 4.3.1 and it dose work, so why it happend?

Compiling standalone QGIS application with qtopia core

Hi ,

i compiled the application but still it showing the following errors:

In file included from main.cpp:9:
/home/saravanan/QGIS/qgis_0.9.1/src/gui/qgsmapcanvas.h:30:24: error: QDomDocument: No such file or directory
In file included from /usr/include/c++/4.1.0/backward/deque.h:59,
from main.cpp:19:
/usr/include/c++/4.1.0/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.
main.cpp:65:2: warning: no newline at end of file
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsapplication.h:21: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsproviderregistry.h:38: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgis.h:34: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgsrenderer.h:37: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgssinglesymbolrenderer.h:26: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgssinglesymbolrenderer.h:63: error: ‘QgsSingleSymbolRenderer’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgssinglesymbolrenderer.h:63: error: non-member function ‘const QgsSymbol* symbol()’ cannot have cv-qualifier
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgssinglesymbolrenderer.h: In function ‘const QgsSymbol* symbol()’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgssinglesymbolrenderer.h:65: error: ‘mSymbol’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgssinglesymbolrenderer.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgssinglesymbolrenderer.h:68: error: ‘QgsSingleSymbolRenderer’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgssinglesymbolrenderer.h:68: error: non-member function ‘bool needsAttributes()’ cannot have cv-qualifier
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsmaplayerregistry.h:36: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:26: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:127: error: expected ‘,’ or ‘...’ before ‘&’ token
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:127: error: ISO C++ forbids declaration of ‘QgsPoint’ with no type
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:127: error: ‘bool operator==(int)’ must have an argument of class or enumerated type
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:127: error: ‘bool operator==(int)’ must take exactly two arguments
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h: In function ‘bool operator==(int)’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:129: error: ‘p1’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:129: error: ‘p2’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:127: warning: unused parameter ‘QgsPoint’
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:135: error: expected ‘,’ or ‘...’ before ‘&’ token
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:135: error: ISO C++ forbids declaration of ‘QgsPoint’ with no type
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h: In function ‘std::ostream& operator<<(std::ostream&, int)’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:138: error: ‘p’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:135: warning: unused parameter ‘QgsPoint’
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:35: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:132: error: expected initializer before ‘::’ token
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:136: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘void setXmin(double)’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:138: error: ‘xmin’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:141: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘void setXmax(double)’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:143: error: ‘xmax’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:146: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘void setYmin(double)’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:148: error: ‘ymin’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:151: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘void setYmax(double)’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:153: error: ‘ymax’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:156: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:156: error: non-member function ‘double xMax()’ cannot have cv-qualifier
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘double xMax()’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:158: error: ‘xmax’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:161: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:161: error: non-member function ‘double xMin()’ cannot have cv-qualifier
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘double xMin()’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:163: error: ‘xmin’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:166: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:166: error: non-member function ‘double yMax()’ cannot have cv-qualifier
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘double yMax()’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:168: error: ‘ymax’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:171: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:171: error: non-member function ‘double yMin()’ cannot have cv-qualifier
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘double yMin()’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:173: error: ‘ymin’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:176: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:176: error: non-member function ‘double width()’ cannot have cv-qualifier
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘double width()’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:178: error: ‘xmax’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:178: error: ‘xmin’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:181: error: ‘QgsRect’ has not been declared
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:181: error: non-member function ‘double height()’ cannot have cv-qualifier
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘double height()’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:183: error: ‘ymax’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:183: error: ‘ymin’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:186: error: ‘QgsPoint’ does not name a type
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:190: error: expected ‘,’ or ‘...’ before ‘&’ token
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:190: error: ISO C++ forbids declaration of ‘QgsRect’ with no type
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: In function ‘std::ostream& operator<<(std::ostream&, int)’:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:190: error: redefinition of ‘std::ostream& operator<<(std::ostream&, int)’
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgspoint.h:135: error: ‘std::ostream& operator<<(std::ostream&, int)’ previously defined here
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:192: error: ‘r’ was not declared in this scope
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h: At global scope:
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsrect.h:190: warning: unused parameter ‘QgsRect’
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsmaplayer.h:42: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsfeature.h:47: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/core/qgsvectorlayer.h:67: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/gui/qgsmapcanvas.h:61: error: invalid function declaration
/home/saravanan/QGIS/qgis_0.9.1/src/gui/qgsmapcanvas.h:92: error: invalid function declaration
main.cpp: In function ‘int main(int, char**)’:
main.cpp:25: error: ‘QgsApplication’ was not declared in this scope
main.cpp:25: error: expected `;' before ‘app’
main.cpp:32: error: ‘QgsProviderRegistry’ has not been declared
main.cpp:32: error: invalid type in declaration before ‘(’ token
main.cpp:32: error: cannot convert ‘QString’ to ‘int’ in initialization
main.cpp:34: error: invalid use of undefined type ‘struct QgsVectorLayer’
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgsrenderer.h:22: error: forward declaration of ‘struct QgsVectorLayer’
main.cpp:35: error: ‘QgsSingleSymbolRenderer’ was not declared in this scope
main.cpp:35: error: ‘mypRenderer’ was not declared in this scope
main.cpp:35: error: expected type-specifier before ‘QgsSingleSymbolRenderer’
main.cpp:35: error: expected `;' before ‘QgsSingleSymbolRenderer’
main.cpp:37: error: invalid use of undefined type ‘struct QgsVectorLayer’
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgsrenderer.h:22: error: forward declaration of ‘struct QgsVectorLayer’
main.cpp:38: error: invalid use of undefined type ‘struct QgsVectorLayer’
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgsrenderer.h:22: error: forward declaration of ‘struct QgsVectorLayer’
main.cpp:48: error: ‘QgsMapLayerRegistry’ has not been declared
main.cpp:48: error: expected initializer before ‘->’ token
main.cpp:53: error: ‘QgsMapCanvas’ was not declared in this scope
main.cpp:53: error: ‘mypMapCanvas’ was not declared in this scope
main.cpp:53: error: expected type-specifier before ‘QgsMapCanvas’
main.cpp:53: error: expected `;' before ‘QgsMapCanvas’
main.cpp:54: error: invalid use of undefined type ‘struct QgsVectorLayer’
/home/saravanan/QGIS/qgis_0.9.1/src/core/renderer/qgsrenderer.h:22: error: forward declaration of ‘struct QgsVectorLayer’
main.cpp:64: error: ‘app’ was not declared in this scope
main.cpp:32: warning: unused variable ‘instance’
main.cpp: At global scope:
main.cpp:22: warning: unused parameter ‘argc’
main.cpp:22: warning: unused parameter ‘argv’
make: *** [main.o] Error 1

can anyone provide me any suggestions or solutions for this ?

with regards,

saravanan

Compiling standalone QGIS application with qtopia core

hi everyone,

i finnaly got it compiled against the QGis header files. but now there is the following error:

main.cpp:54: error: ‘class QgsVectorLayer’ has no member named ‘setVisible’
main.cpp:63: error: no matching function for call to ‘QgsMapCanvas::setLayerSet(std::deque >&)’
/home/saravanan/QGIS/qgis_one/install_path/include/qgis/qgsmapcanvas.h:106: note: candidates are: void QgsMapCanvas::setLayerSet(QList&)
.

i searched in the QgsVectorLayer API documentation, there is no member called "setVisible(true)" in QgsVectorLayer.

can anyone provide me any suggestion or solutions for this ?

saravanan