1

I have been working on a Qt5 Widgets based application. I'm required to display maps (vector charts) in my application on a widget and for that purpose I've decided to use the QGIS library in my project. I've found very little material on the internet on setting up the QGISenvironment and running a plain map based application. I've also seen various posts from Stack Overflow and Stack Exchange but many of them are either old and based on older versions of Qt and QGIS or have partial solutions that were not fully addressed. I've set up my QGIS environment using this recent post Using QGIS C++ API In Custom GIS Application as the configurations were very close to mine, but still my application either crashes or exits with code -1.

My Development Environment:

  • Windows 10 64 bit
  • Qt Creator 4.9.1 based on Qt 5.12.3 (MSVC 2017, 32 bit)
  • Qt 5.13.0
  • MSVC 2015 - 64 bit
  • OSGeo4W64 installed with (qgis, qgis-ltr, qgis-ltr-dev, gdal, gdal-dev, proj, proj-dev, grass, python37, Qt5). This is a slightly old OSGeo4W I installed (osgeo4w-setup-x86_64-v1.exe) from http://download.osgeo.org/osgeo4w/

My Code:

.pro

INCLUDEPATH += C:\OSGeo4W64\include
INCLUDEPATH += C:\OSGeo4W64\apps\qgis-ltr-dev\include
LIBS += -L"C:\OSGeo4W64\apps\qgis-ltr-dev\lib" -lqgis_core -lqgis_gui

main.cpp

#include <qgsapplication.h>

int main(int argc, char *argv[])
{
    QgsApplication app(argc, argv, true);

    QString PREFIX_PATH = "C:\\OSGeo4W64\\apps\\qgis-ltr-dev";

    QgsApplication::setPrefixPath(PREFIX_PATH);
    QgsApplication::initQgis();

    int exitCode= app.exec();

    QgsApplication::exitQgis();

    return exitCode;
}

Batch Script to start Qt Creator with the Environment variables:

PATH=C:\OSGEO4~1\apps\qgis-ltr-dev\bin;C:\OSGEO4~1\apps\gdal-dev\pymod3\scripts;C:\OSGEO4~1\apps\Python37;C:\OSGEO4~1\apps\Python37\Scripts;C:\OSGEO4~1\apps\gdal-dev\bin;C:\OSGEO4~1\apps\proj-dev\bin;C:\OSGEO4~1\apps\qt5\bin;C:\OSGEO4~1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBem;%PATH%
set GDAL_DATA=C:\OSGEO4~1\apps\gdal-dev\share\gdal
set GDAL_DRIVER_PATH=C:\OSGEO4~1\apps\gdal-dev\bin\gdalplugins
set GDAL_FILENAME_IS_UTF8=YES
set GEOTIFF_CSV=C:\OSGEO4~1\share\epsg_csv
set JPEGMEM=1000000
set OSGEO4W_ROOT=C:\OSGEO4~1
set PROJ_LIB=C:\OSGEO4~1\apps\proj-dev\share\proj
set PYTHONHOME=C:\OSGEO4~1\apps\Python37
set PYTHONPATH=C:\OSGEO4~1\apps\gdal-dev\pymod3\lib\site-packages;C:\OSGEO4~1\apps\Python37;C:\OSGEO4~1\apps\Python37\Scripts
set QGIS_PREFIX_PATH=C:/OSGEO4~1/apps/qgis-ltr-dev
set QT_PLUGIN_PATH=C:\OSGEO4~1\apps\qgis-ltr-dev\qtplugins;C:\OSGEO4~1\apps\qt5\plugins
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set O4W_QT_PREFIX=C:/OSGEO4~1/apps/Qt5
set O4W_QT_BINARIES=C:/OSGEO4~1/apps/Qt5/bin
set O4W_QT_PLUGINS=C:/OSGEO4~1/apps/Qt5/plugins
set O4W_QT_LIBRARIES=C:/OSGEO4~1/apps/Qt5/lib
set O4W_QT_TRANSLATIONS=C:/OSGEO4~1/apps/Qt5/translations
set O4W_QT_HEADERS=C:/OSGEO4~1/apps/Qt5/include

start "Qt Creator" /B  D:\Qt\Qt5.13.0\Tools\QtCreator\bin\qtcreator.exe %*

When I start the application, the application output console shows following problems:

(QgsProviderRegistry::init) Checking C:/OSGeo4W64/apps/qgis-ltr-dev/plugins/grassplugin7.dll: ...invalid (lib not loadable) : Cannot load library C:/OSGeo4W64/apps/qgis-ltr-dev/plugins/grassplugin7.dll: The specified module could not be found.
(QgsProviderRegistry::init) Checking C:/OSGeo4W64/apps/qgis-ltr-dev/plugins/grassprovider7.dll: ...invalid (lib not loadable) : Cannot load library C:/OSGeo4W64/apps/qgis-ltr-dev/plugins/grassprovider7.dll: The specified module could not be found.
(QgsProviderRegistry::init) Checking C:/OSGeo4W64/apps/qgis-ltr-dev/plugins/grassrasterprovider7.dll: ...invalid (lib not loadable) : Cannot load library C:/OSGeo4W64/apps/qgis-ltr-dev/plugins/grassrasterprovider7.dll: The specified module could not be found.
(QgsProviderRegistry::init) Loaded 23 providers
(QgsAuthManager::isDisabled) Authentication system DISABLED: QCA's qca-ossl (OpenSSL) plugin is missing
QApplication::exec: Please instantiate the QApplication object first

and lastly it prints:

.../qgis_demo.exe exited with code -1

Can you point out what is wrong in my code and/or configuration?

0

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.