qt - 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 ?
解决方案
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.
推荐阅读
- python - 使用 Holoviews Holomap 绘制各天的堆积面积图
- node.js - [:^punct] 的 Postgresql 无效类
- laravel - Laravel Valet 共享错误:“dial tcp [...] no such host”
- php - spl_autoload_register 如何在内部工作
- javascript - 未捕获的类型错误:无法读取 select2 中 null 的属性“替换”
- android - 如何使用 bitbucket-pipelines 定位 apk 文件?
- c# - 当实体在不同的项目中时,为什么 Mediatr 不解析方法?
- excel - 兰德给出#n/a
- python - 如何在读取之前清除字符串并将str转换为int
- ios - Healthkit per hour 包含步数、距离和卡路里的活动摘要?