Abstract: The configuration steps for QT to develop QGIS are similar to those for Visual Studio 2015. The biggest difference is that Visual ...
The configuration steps for QT to develop QGIS are similar to those for Visual Studio 2015. The biggest difference is that Visual Studio 2015 is configured in settings, and QT is configured in its pro file. See the installation of Qt and QGIS here.
1.Create a Qt project
Create a new Qt project according to your needs and run it to generate an exe file.
2.Modify the pro file
Change your pro file to the following contents. All directories need to be modified according to your actual situation.
#Add xml and 3dcore (3d display)
QT += core gui xml 3dcore
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
#Attach Include Directory
INCLUDEPATH += "D:\Software\OSGeo4W\include"
INCLUDEPATH += "D:\Software\OSGeo4W\apps\qgis-ltr-dev\include"
#The directory of the additional library is followed by the lib files used in the directory, such as - lqgis_ Core is qgis_ core.lib
LIBS += -L"D:\Software\OSGeo4W\apps\qgis-ltr-dev\lib" -lqgis_core -lqgis_gui -lqgis_3d
#Preprocessor definition
DEFINES += _USE_MATH_DEFINES
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
3.Configure environment variables
Configure the following directories in the environment variable path
(specific directories are modified according to your own).
D:\Software\OSGeo4W\bin
D:\Software\OSGeo4W\apps\qgis-ltr-dev\bin
D:\Software\OSGeo4W\apps\Qt5\bin
D:\Software\OSGeo4W\apps\gdal-dev\bin
D:\Software\OSGeo4W\apps\proj-dev\bin
4.Copy relevant documents
The specific directory is modified according to your own.
- Copy the platforms directory in the
D:SoftwareQt5.12.12msvc2015_64pluginsplatforms
to the plugins directory under the exe file directory (if not, create it yourself). - Retrieve all files in the
D:SoftwareOSGeo4Wappsqgis-ltr-devplugins
directory to the same level plugins directory as exe files - Copy the gdal directory in
D:SoftwareOSGeo4Wshare to the share
of the same level of exe file (if not, create it yourself).
5.Create conf file
Create a new qt.conf file in the exe file directory, as shown below.
[Paths]
Prefix=.
6.Operation
Run after configuration.