I am working with qgis api c++ 2.8.2, in c++/QT 4.5 I try to save my List of QgsField but I have the error message : no matching for call to 'QgsVectorFileWriter' I took the sample from here :


Here is my code in C++

QList <QgsField> lMyAttribField;
QgsVectorFileWriter * writer;
writer = QgsVectorFileWriter("/tmp/myshapes.shp", "CP1250", lMyAttribField, QGis::WKBPoint, "0", "ESRI Shapefile");

I have the same eror if I delete the * in the declaration of writer

I don't understand what's i forget ?

2 Answers 2


If you review the API (http://qgis.org/api/classQgsVectorFileWriter.html) for QgsVectorFileWriter, the constructor looks like:

QgsVectorFileWriter::QgsVectorFileWriter    (   const QString &     vectorFileName,
        const QString &     fileEncoding,
        const QgsFields &   fields,
        QGis::WkbType   geometryType,
        const QgsCoordinateReferenceSystem *    srs,
        const QString &     driverName = "ESRI Shapefile",
        const QStringList &     datasourceOptions = QStringList(),
        const QStringList &     layerOptions = QStringList(),
        QString *   newFilename = 0,
        SymbologyExport     symbologyExport = NoSymbology 

The likely problem is that you are passing a string ("0") instead of a pointer to QgsCoordinateReferenceSystem for the srs argument. In Nathan's follow-up he passed in null (note 0, not "0")


Here is the code without error

QgsVectorFileWriter * writer;
writer = new QgsVectorFileWriter("/tmp/myshapes.shp",
                                    "ESRI Shapefile");

where MyQgsFields is a QgsFields, and mpMapCanvas->mQgsCoordinate is a QgsCoordinateRefenceSystem

it works when i launch my application and add a tracks a file was created in /tmp . i can open it in QGIS without error but at this step it contains nothing , no data

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.