Search code examples
qtgdal

Qt gdal Error: ‘Open’ is not a member of ‘OGRSFDriverRegistrar’


I am working on a Qt project with gdal libraries.

Qt5.9.1. Ubuntu 16.10 LTS.

I am getting an error and I have no clue what is going wrong.

#include <QCoreApplication>
#include <QFile>
#include "ogrsf_frmts.h"

int main(int argc, char *argv[])
{
    OGRRegisterAll();
    OGRDataSource *source;

    source = OGRSFDriverRegistrar::Open( <path to s57 file>, FALSE );
    if( source == NULL )
    {
        printf( "Open failed.\n" );
        exit( 1 );
    }
}

I am getting the following error:

main.cpp:11: error: 
'Open' is not a member of 'OGRSFDriverRegistrar';

source = OGRSFDriverRegistrar::Open( <path to s57 chart file>, FALSE );

Can anybody please help me in resolving the error ?


Solution

  • The class OGRSFDriverRegistrar is marked as a Legacy class and as such is deprecated.

    The docs suggest using GDALDriverManager() as quoted here:

    Use GDALDriverManager in your new code ! This class may be removed in a later release.

    Which version of GDAL are you using? It could be that OGRSFDriverRegistrar is already removed.

    Anyway removed or not, I suggest you should try updating your code with GDALDriverManager.

    EDIT: Added example.

    #include "gdal_priv.h"
    #include "cpl_conv.h" // for CPLMalloc()
    int main()
    {
        GDALDataset  *poDataset;
        GDALAllRegister();
        poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
        if( poDataset == NULL )
        {
            ...;
        }
    }
    

    Taken from GDAL API tutorial.