Cannot find qgsapplication.h and other header files

Deadly 提交于 2020-01-05 21:22:01

问题


I am using QtCreator and QGIS 2.6 to build a standalone C++ application.

The problem I am encountering is the project cannot find all the necessary header files.

My .pro file looks lie the following:

QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TestQgis2
TEMPLATE = app
SOURCES += main.cpp
#HEADERS +=YOUR HEADERS
#FORMS += YOUR FORMS
#RESOURCES += images/images.qrc

win32:CONFIG(Release, Debug|Release) {
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/lib/" -lQtCore4
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/lib/" -lQtGui4
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/lib/" -lQtXml4
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/apps/qgis/bin/" -lqgis_core
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/apps/qgis/bin/" -lqgis_gui
}
else:win32:CONFIG(Debug, Debug|Release) {
 PRE_TARGETDEPS += C:/Program Files (x86)/QGIS Brighton/lib/QtCored4.lib
 PRE_TARGETDEPS += C:/Program Files (x86)/QGIS Brighton/lib/QtGuid4.lib
 PRE_TARGETDEPS += C:/Program Files (x86)/QGIS Brighton/lib/QtXmld4.lib
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/lib/" -lQtCored4
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/lib/" -lQtGuid4
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/lib/" -lQtXmld4
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/apps/qgis/bin/" -lqgis_core
 LIBS += -L"C:/Program Files (x86)/QGIS Brighton/apps/qgis/bin/" -lqgis_gui
}
win32:{
 INCLUDEPATH += C:/Program Files (x86)/QGIS Brighton/include
 DEPENDPATH +=  C:/Program Files (x86)/QGIS Brighton/include
# INCLUDEPATH += C:/OSGeo4W/apps/qgis-dev/include
# DEPENDPATH += C:/OSGeo4W/apps/qgis-dev/include
 DEFINES += GUI_EXPORT=__declspec(dllimport) CORE_EXPORT=__declspec(dllimport)
}
unix {
 LIBS += -L/usr/local/lib/ -lqgis_core -lqgis_gui
 LIBS += -L/usr/local/lib/qgis/plugins/ -lgdalprovider
 INCLUDEPATH += /usr/local/include/qgis
 DEFINES += GUI_EXPORT= CORE_EXPORT=
}

And in my program, none of the following headers can be found:

#include "<"qgsapplication.h">"

#include "<"qgsproviderregistry.h">"

#include "<"qgssinglesymbolrenderer.h">"

#include "<"qgsmaplayerregistry.h">"

#include "<"qgsvectorlayer.h">"

#include "<"qgsmapcanvas.h">"

And from the installed qgis folder, I cannot find any of the above header files.

Any help is appreciated.


回答1:


To debug your application I think you must add RelWithDebInfo mode in your project file:

QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = TestQgis2
TEMPLATE = app
SOURCES += main.cpp
#HEADERS +=YOUR HEADERS
#FORMS += YOUR FORMS
#RESOURCES += images/images.qrc

win32:CONFIG(Release, Debug|Release, RelWithDebInfo) {
 LIBS += -L"C:/OSGeo4W/apps/qgis/lib/" -lQtCore4
 LIBS += -L"C:/OSGeo4W/apps/qgis/lib/" -lQtGui4
 LIBS += -L"C:/OSGeo4W/apps/qgis/lib/" -lQtXml4
 LIBS += -L"C:/OSGeo4W/apps/qgis/bin/" -lqgis_core
 LIBS += -L"C:/OSGeo4W/apps/qgis/bin/" -lqgis_gui
}
else:win32:CONFIG(Debug, Debug|Release, RelWithDebInfo) {
 PRE_TARGETDEPS += C:/OSGeo4W/lib/QtCored4.lib
 PRE_TARGETDEPS += C:/OSGeo4W/lib/QtGuid4.lib
 PRE_TARGETDEPS += C:/OSGeo4W/lib/QtXmld4.lib
 LIBS += -L"C:/OSGeo4W/lib/" -lQtCored4
 LIBS += -L"C:/OSGeo4W/lib/" -lQtGuid4
 LIBS += -L"C:/OSGeo4W/lib/" -lQtXmld4
 LIBS += -L"C:/OSGeo4W/apps/qgis/bin/" -lqgis_core
 LIBS += -L"C:/OSGeo4W/apps/qgis/bin/" -lqgis_gui
}
win32:{
 INCLUDEPATH += C:/OSGeo4W/include
 DEPENDPATH +=  C:/OSGeo4W/include
# INCLUDEPATH += C:/OSGeo4W/apps/qgis/include
# DEPENDPATH += C:/OSGeo4W/apps/qgis/include
 DEFINES += GUI_EXPORT=__declspec(dllimport) CORE_EXPORT=__declspec(dllimport)
}
unix {
 LIBS += -L/usr/local/lib/ -lqgis_core -lqgis_gui
 LIBS += -L/usr/local/lib/qgis/plugins/ -lgdalprovider
 INCLUDEPATH += /usr/local/include/qgis
 DEFINES += GUI_EXPORT= CORE_EXPORT=
}



回答2:


which one is line 28?

if it is this:

win32:CONFIG(Release, Debug|Release, RelWithDebInfo)

you can replace it with:

win32:CONFIG(Release, RelWithDebInfo|Release)

and replace this:

else:win32:CONFIG(Debug, Debug|Release, RelWithDebInfo)

with:

else:win32:CONFIG(RelWithDebInfo, RelWithDebInfo|Release)

because Qgis ant Qt libraries are compiled with Release mode so if you want to debug your application you must use RelWithDebInfo mode



来源:https://stackoverflow.com/questions/26920574/cannot-find-qgsapplication-h-and-other-header-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!