1

I am working on a project in c++/QT4.8.5 based on the api c++ 2.8.2 of QGis It is a stand alone application

I had to get information of a layer by clicking on it in the canvas

So I decide to use the class QgsMapToolIdentify ( i saw some sample in the book building mapping application with Qgis from Erik Westra )

here is my code :

mIdentify =new QgsMapToolIdentify(mpMapCanvas);
QList <struct IdentifyResult *> lResultList;

lResultList = mIdentify->identify(lCoord.x(),lCoord.y(), TopDownStopAtFirst, VectorLayer);

but when I want to build it i have an error on the enum value TopDownStopAtFirst and VectorLayer

the error message :

src/IHM/mainwindow.cpp:174:83: error: ‘VectorLayer’ was not declared in this scope lResultList = mIdentify->identify(lCoord.x(),lCoord.y(), TopDownStopAtFirst, VectorLayer);

and the same message for the TopDownStopAtFirst

I have included the header qgsmaptoolidentfy.h in main.cpp.

2 Answers 2

3

You have to specify the parent class name of the enum when using it outside its scope.

lResultList = mIdentify->identify(lCoord.x(),lCoord.y(), QgsMapToolIdentify::TopDownStopAtFirst, QgsMapToolIdentify::VectorLayer);

But this is really more of a general C++ issue than GIS specific. If you run into more of these, please ask them on https://stackoverflow.com/ .

1
  • ok, i will correct that and post the correction if it works
    – ainardi
    Sep 23, 2015 at 12:28
2

in fact there is another error here is the code working :

mIdentify =new QgsMapToolIdentify(mpMapCanvas);
mIdentify->activate();
QList < QgsMapToolIdentify::IdentifyResult > lResultList;
lResultList.append(mIdentify->identify(lCoord.x(),lCoord.y(),QgsMapToolIdentify::TopDownStopAtFirst, QgsMapToolIdentify::VectorLayer));

qDebug() << "size identify Qlist =" << lResultList.size();

the qdebug show the number of element in the qlist each time the function has been called. In my application, the function is called when a subfunction is activated and then when I left click on the map i have a result

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.