我正在尝试使用 QGIS API 和预定义的 QGIS 项目文件创建一个 Windows 窗体控件,以便我可以在 Windows 窗体控件上设置 X 和 Y 属性,并且 QGIS API 将在控件中显示预定义的地图数据,聚焦于提供的坐标。
使用 QgsProject::instance()->read() 似乎会导致未处理的异常(访问冲突读取位置 0x00000000),因此我尝试逐行挑选实际代码。 qgsproject.cpp 的一部分处理从项目文件中提取图层,然后将它们添加到地图画布中:
QgsMapLayer *mapLayer = null;
if(type=="vector")
mapLayer = new QgsVectorLayer;
else if(type==""raster")
mapLayer = new QgsRasterLayer;
其中 type 是元素“type”属性的值。
当我尝试在 Visual Studio 项目中编译它时,它抱怨这两种类型的地图层都没有默认构造函数。我可用的唯一构造函数需要路径和基名,并且似乎实际上不起作用(因此尝试使用与 gui 相同的方法,因为项目文件确实加载在完整的应用程序 gui 中)。
QgsRasterLayer 的默认构造函数似乎不是私有成员函数。有谁知道我将如何进行编译?
谢谢,
瑞克
I'm trying to create a Windows Forms control using the QGIS API and a pre-defined QGIS project file, so that I can set X and Y properties on the Windows Forms control and the QGIS API will show the predefined map data in the Control, focused at the supplied coordinates.
Using QgsProject::instance()->read() seems to cause an unhandled exception (Access violation reading location 0x00000000), so I'm trying to pick through the actual code line by line. There's a portion of qgsproject.cpp that deals with extracting layers from a project file and then adding them to the map canvas that says:
QgsMapLayer *mapLayer = null;
if(type=="vector")
mapLayer = new QgsVectorLayer;
else if(type==""raster")
mapLayer = new QgsRasterLayer;
Where type is the value of the element 'type' attribute.
When I try to compile this in my Visual Studio project, it complains that there is no default constructor for either type of map layer. The only constructors avaiable to me require paths and basenames, and don't seem to actually work (hence trying to use the same methods as the gui given that the project file does load in the full application gui).
The default constructor for the QgsRasterLayer doesn't even seem to be a private member function. Does anyone know how aI would go about making this compile?
Thanks,
Rik
发布评论
评论(1)
只是猜测:您使用 Visual Studio 2008 吗? http://hub.qgis.org/wiki /quantum-gis/Building_QGIS_from_Source#Building-with-Microsoft-Visual-Studio 表示 QGIS 二进制文件(我假设您正在使用它们)是使用 Visual Studio 构建的2008 - 如果您使用不同的编译器版本,您可能会遇到运行时混合问题。
Just a guess: Do you use Visual Studio 2008? http://hub.qgis.org/wiki/quantum-gis/Building_QGIS_from_Source#Building-with-Microsoft-Visual-Studio indicates that the QGIS binaries (I assume that you're using them) are build using Visual Studio 2008 - if you use a different compiler version, you might encounter runtime mixing problems.