1. System requirements
Windows 10 professional
2. Install Visual Studio 2015
from Visual Studio official website Find the version you need and download it according to the number of computer bits, language and file type. I downloaded Visual Studio Professional 2015 with Update 3. After downloading, click the program to install.
If only the secondary development of QGIS is carried out, select custom installation when installing VS2015, and only select "Visual C + +". As shown in the figure below.
2. Install Qt5 twelve
stay Qt official website Under the open source development page of, find Qt Online Installer, click download, and then install. (Qt account is required for downloading, and an account should be applied in advance)
After clicking online installation, select the installation location and other items according to your own needs. When selecting components to download, try to select the LTS version. Here are the components I selected during installation.
MSVC 2015 64bit corresponds to VS2015. If it is VS2017, you can choose MSVC 2017.
Other options are selected according to your needs. Wait a while for the installation to complete.
3. Install qgis3 sixteen
stay QGIS official website To find a suitable download version, it is best to download QGIS in OSGeo4W online installer. Here, take QGIS in OSGeo4W as an example for installation.
Click Install, select Advanced Install, and then go all the way to Next. Until you choose the download URL.
Select a web address to proceed to the next step. Then enter qgis in the search box to display all installable components. For all components, there are Skip and related versions. You can select what you need. Here are all the components of 3.16.16-1 selected.
Then download, the network speed is moving, and it takes quite a long time.
4. Configure Visual Studio 2015 Qt plug-in
Open Visual Studio 2015, search Qt in tools - > extensions and updates - > online, and then install Qt plug-in.
After restarting the software, you will find "Qt VS Tools" in the toolbar, click and find "options" - > "versions" to configure Qt, and the configuration folder shall be subject to your own installation location.
5. Run QGIS program
Create a new Qt project "QGISTest".
5.1 project documents
main.cpp
#include "QGISTest.h" //#include <QtWidgets/QApplication> #include <qgsapplication.h> int main(int argc, char *argv[]) { QgsApplication a(argc, argv, true); // The path here should be changed to your own QGIS installation path QgsApplication::setPrefixPath("D:/Software/OSGeo4W/apps/qgis-ltr-dev", true); QgsApplication::initQgis(); //Initialize QGIS application QGISTest w; w.show(); return a.exec(); }
QGISTest.h
#pragma once #include <QtWidgets/QMainWindow> #include "ui_QGISTest.h" #include <qmenu.h> #include <qaction.h> #include <qgsmapcanvas.h> class QGISTest : public QMainWindow { Q_OBJECT public: QGISTest(QWidget *parent = Q_NULLPTR); private: Ui::QGISTestClass ui; private: // create the menus and then add the actions to them. QMenu *fileMenu; QAction *openFileAction; //map canvas QgsMapCanvas *mapCanvas; QList<QgsMapLayer *> layers; public slots: void on_openFileAction_triggered(); // public: void addVectorLayer(); };
QGISTest.cpp
#include "QGISTest.h" #include <qmenubar.h> #include <qmessagebox.h> #include <qfiledialog.h> #include <qgsvectorlayer.h> QGISTest::QGISTest(QWidget *parent) : QMainWindow(parent) { //ui.setupUi(this); this->resize(600, 400); // create the menus and then add the actions to them. fileMenu = this->menuBar()->addMenu("File"); openFileAction = new QAction("Open", this); this->connect(openFileAction, SIGNAL(triggered(bool)), this, SLOT(on_openFileAction_triggered())); fileMenu->addAction(openFileAction); // initialize the map canvas mapCanvas = new QgsMapCanvas(); this->setCentralWidget(mapCanvas); mapCanvas->setCanvasColor(QColor(255, 255, 255)); mapCanvas->setVisible(true); mapCanvas->enableAntiAliasing(true); } void QGISTest::on_openFileAction_triggered() { addVectorLayer(); } void QGISTest::addVectorLayer() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open shape file"), "", "*.shp"); QStringList temp = fileName.split('/'); QString basename = temp.at(temp.size() - 1); QgsVectorLayer* vecLayer = new QgsVectorLayer(fileName, basename, "ogr"); if (!vecLayer->isValid()) { QMessageBox::critical(this, "error", QString("layer is invalid: \n") + fileName); return; } mapCanvas->setExtent(vecLayer->extent()); layers.append(vecLayer); mapCanvas->setLayers(layers); mapCanvas->refresh(); }
5.2 relevant configuration
5.2.1 additional contents
Click "QT vs tools" - > "Qt Project Settings" - > "C/C + +" > "general", and add the following directory to the additional included directory (modify according to your installation location).
D:\Software\Qt\5.12.12\msvc2015_64\include\QtXml
D:\Software\OSGeo4W\include
D:\Software\OSGeo4W\apps\qgis-ltr-dev\include
5.2.2 additional Library Directory
Click "QT vs tools" - > "Qt Project Settings" - > "linker" - > "general", and add the following directory to the directory of additional library (modify according to your installation location).
D:\Software\Qt\5.12.12\msvc2015_64\lib
D:\Software\OSGeo4W\apps\qgis-ltr-dev\lib
5.2.3 additional dependencies
Click "QT vs tools" - > "Qt Project Settings" - > "linker" - > "input", and add the following contents to the additional dependencies.
Qt5Core.lib
Qt5Widgets.lib
Qt5Xml.lib
Qt5Gui.lib
qgis_core.lib
qgis_gui.lib
qgis_app.lib
5.2.4 definition of preprocessor
Click "QT vs tools" - > "Qt Project Settings" - > "C/C + +" > "preprocessor", add "_use_math_definitions" in the definition of preprocessor and separate it from other items with semicolons.
5.2.5 environmental variables
Add the following directory into the system environment variable path (modify it according to your installation location).
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
Restart when finished.
5.3 operation results
Click "file" - > "Open" and find it The shp file is opened. The following figure shows the effect.
6. Other issues
6.1 Qt plug-in not loaded
Qt plug-in may not be loaded at runtime.
At this time, find the D:\Software\OSGeo4W\apps\Qt5\plugins\platforms folder in the QGIS installation directory (modify it according to your installation location), and copy it to the same directory of the executable (. exe).