I am working in c++/QT 4.8.5 and the api c++ qgis 2.8.2

In my application i had top select layer with the mouse click button to get attribute value and show them in a popup windows

I see in the api online documentation taht there is two classes :

QgsMapToolIdentifyFeature and QgsMapToolIdentify

can i use one of them to do what i want to do in my application or there is another to do it ?


After searching in stackexchange, on the web, and in the book "building mapping application with QGis", and try to understand here is a simple solution taht you can use if you want this is a small sample of use In my application, I load a S57 map file, When i activate the selectionLayer function via the maptool button, each time I cleck on the map the last qdebug display all the information i need

the code :

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

qDebug() << "size identify Qlist =" << lResultList.size();
// get the structure
QgsMapToolIdentify::IdentifyResult lStructResult = lResultList.at(0);

// get the map Layer from the structure
QgsMapLayer *lMapLayer = lStructResult.mLayer;
// get the feature from the structure
QgsFeature lFeature = lStructResult.mFeature;
// get the label
QString lLabel = lStructResult.mLabel;

qDebug() << " Label = " << lLabel << "  lFeatureId = " << lFeature.id() << "  MapLayerName = " << lMapLayer->name();

it is a sample test code , there is no check if the QList is empty

| 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.