bug8232.cpp

Daniel Vaz, 2013-07-07 03:02 PM

Download (807 Bytes)

 
1
#include <QDebug>
2
#include <QList>
3
#include <QVariant>
4

    
5
#include "qgis.h"
6
#include "qgsapplication.h"
7
#include "qgsvectorlayer.h"
8
#include "qgsvectordataprovider.h"
9

    
10
int main(int argc, char *argv[]) {
11
  QgsApplication app(argc, argv, false);
12
  app.setPrefixPath("/usr/local", true);
13
  app.initQgis();
14
  // load a layer
15
  QgsVectorLayer vlayer("polygons.shp", "layer_name", "ogr");
16
  if ( vlayer.isValid() ) {
17
    qDebug("layer is valid");
18
    // get the data provider
19
    QgsVectorDataProvider *vprovider = vlayer.dataProvider();
20
    // get index of field 'name' 
21
    int name_index = vprovider->fieldNameIndex("id");
22
    // there are NULL values in the field 'name' on sample dataset
23
    QList<QVariant> uniques;
24
    vprovider->uniqueValues(name_index, uniques);
25
    qDebug() << uniques;
26
  }
27
  return 0;
28
}