我正在使用QGIS API创建一个简单的qt应用程序,以加载一个简单的地图或形状文件。但是目前,我仍坚持使用qgis头文件。代码很简单:

//
// QGIS Includes
//
#include <qgis/qgsapplication.h>
//
// Qt Includes
//
#include <QString>
#include <QApplication>
#include <QWidget>
int main(int argc, char ** argv)
{
    // Start the Application
    QgsApplication app(argc, argv, true);
    QApplication a(argc, argv);
    return app.exec();
}


我只是尝试在第一步中包含qgsapplication。但是它显示了很多错误(“问题”窗口中有38个错误),这是编译输出:

15:44:09: Running steps for project Test...
15:44:09: Configuration unchanged, skipping qmake step.
15:44:09: Starting: "/usr/bin/make"
g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I../Test -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I/usr/include/qgis -I. -I. -I../Test -I. -o main.o ../Test/main.cpp
In file included from /usr/include/qgis/qgsapplication.h:22:0,
from ../Test/main.cpp:4:
/usr/include/qgis/qgis.h:34:19: error: variable 'CORE_EXPORT QGis' has initializer but incomplete type
class CORE_EXPORT QGis
^
/usr/include/qgis/qgis.h:34:19: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
/usr/include/qgis/qgis.h:36:3: error: expected primary-expression before 'public'
public:
^
/usr/include/qgis/qgis.h:36:3: error: expected '}' before 'public'
/usr/include/qgis/qgis.h:36:3: error: expected ',' or ';' before 'public'
/usr/include/qgis/qgis.h:42:22: error: uninitialized const 'QGIS_VERSION_INT' [-fpermissive]
static const int QGIS_VERSION_INT;
^
/usr/include/qgis/qgis.h:244:31: error: 'QGis' is not a class or namespace
static QString toLiteral( QGis::UnitType unit );
^
/usr/include/qgis/qgis.h:246:52: error: 'QGis' is not a class or namespace
static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
^
/usr/include/qgis/qgis.h:246:67: error: expected ',' or '...' before 'defaultType'
static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
^
/usr/include/qgis/qgis.h:248:24: error: 'QGis' is not a class or namespace
static QString tr( QGis::UnitType unit );
^
/usr/include/qgis/qgis.h:250:46: error: 'QGis' is not a class or namespace
static UnitType fromTr( QString literal, QGis::UnitType defaultType = UnknownUnit );
^
/usr/include/qgis/qgis.h:250:61: error: expected ',' or '...' before 'defaultType'
static UnitType fromTr( QString literal, QGis::UnitType defaultType = UnknownUnit );
^
/usr/include/qgis/qgis.h:252:41: error: 'QGis' is not a class or namespace
static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );
^
/usr/include/qgis/qgis.h:252:66: error: 'QGis' is not a class or namespace
static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );
^
/usr/include/qgis/qgis.h:252:88: error: expression list treated as compound expression in initializer [-fpermissive]
static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );
^
/usr/include/qgis/qgis.h:268:25: error: uninitialized const 'DEFAULT_IDENTIFY_RADIUS' [-fpermissive]
static const double DEFAULT_IDENTIFY_RADIUS;
^
/usr/include/qgis/qgis.h:272:25: error: uninitialized const 'DEFAULT_SEARCH_RADIUS_MM' [-fpermissive]
static const double DEFAULT_SEARCH_RADIUS_MM;
^
/usr/include/qgis/qgis.h:275:24: error: uninitialized const 'DEFAULT_MAPTOPIXEL_THRESHOLD' [-fpermissive]
static const float DEFAULT_MAPTOPIXEL_THRESHOLD;
^
/usr/include/qgis/qgis.h:280:25: error: aggregate 'const QColor DEFAULT_HIGHLIGHT_COLOR' has incomplete type and cannot be defined
static const QColor DEFAULT_HIGHLIGHT_COLOR;
^
/usr/include/qgis/qgis.h:290:3: error: expected unqualified-id before 'private'
private:
^
/usr/include/qgis/qgis.h:294:1: error: expected declaration before '}' token
};
^
/usr/include/qgis/qgis.h:44:24: warning: 'QGIS_RELEASE_NAME' defined but not used [-Wunused-variable]
static const char* QGIS_RELEASE_NAME;
^
/usr/include/qgis/qgis.h:46:24: warning: 'QGIS_DEV_VERSION' defined but not used [-Wunused-variable]
static const char* QGIS_DEV_VERSION;
^
/usr/include/qgis/qgis.h:71:20: warning: 'WkbType singleType(WkbType)' defined but not used [-Wunused-function]
static WkbType singleType( WkbType type )
^
/usr/include/qgis/qgis.h:85:20: warning: 'WkbType multiType(WkbType)' defined but not used [-Wunused-function]
static WkbType multiType( WkbType type )
^
/usr/include/qgis/qgis.h:113:17: warning: 'bool isSingleType(WkbType)' defined but not used [-Wunused-function]
static bool isSingleType( WkbType type )
^
/usr/include/qgis/qgis.h:126:17: warning: 'bool isMultiType(WkbType)' defined but not used [-Wunused-function]
static bool isMultiType( WkbType type )
^
/usr/include/qgis/qgis.h:139:16: warning: 'int wkbDimensions(WkbType)' defined but not used [-Wunused-function]
static int wkbDimensions( WkbType type )
^
/usr/include/qgis/qgis.h:165:24: warning: 'const char* vectorGeometryType(GeometryType)' defined but not used [-Wunused-function]
static const char *vectorGeometryType( GeometryType type )
^
/usr/include/qgis/qgis.h:179:24: warning: 'const char* featureType(WkbType)' defined but not used [-Wunused-function]
static const char *featureType( WkbType type )
^
/usr/include/qgis/qgis.h:246:21: warning: 'UnitType fromLiteral(QString, int)' declared 'static' but never defined [-Wunused-function]
static UnitType fromLiteral( QString literal, QGis::UnitType defaultType = UnknownUnit );
^
/usr/include/qgis/qgis.h:250:21: warning: 'UnitType fromTr(QString, int)' declared 'static' but never defined [-Wunused-function]
static UnitType fromTr( QString literal, QGis::UnitType defaultType = UnknownUnit );
^
/usr/include/qgis/qgis.h:252:19: warning: 'fromUnitToUnitFactor' defined but not used [-Wunused-variable]
static double fromUnitToUnitFactor( QGis::UnitType fromUnit, QGis::UnitType toUnit );
^
/usr/include/qgis/qgis.h:280:25: warning: 'DEFAULT_HIGHLIGHT_COLOR' defined but not used [-Wunused-variable]
static const QColor DEFAULT_HIGHLIGHT_COLOR;
^
/usr/include/qgis/qgis.h:284:19: warning: 'DEFAULT_HIGHLIGHT_BUFFER_MM' defined but not used [-Wunused-variable]
static double DEFAULT_HIGHLIGHT_BUFFER_MM;
^
/usr/include/qgis/qgis.h:288:19: warning: 'DEFAULT_HIGHLIGHT_MIN_WIDTH_MM' defined but not used [-Wunused-variable]
static double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM;
^
make: *** [main.o] Error 1
Makefile:220: recipe for target 'main.o' failed
15:44:10: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Test (kit: Desktop)
When executing step "Make"
15:44:10: Elapsed time: 00:01.


有人可以给我一个建议吗?我的环境是OpenSUSE 13.2,QT 4.8.6,QGIS 2.8。

最佳答案

试试看

DEFINES += GUI_EXPORT= CORE_EXPORT=


在* .pro文件中

关于c++ - 包含qgis头文件时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29058873/

10-12 22:45