【Qt】Qt5.14.2 configure yaml-cpp

written in front

This article is to configure the third-party library yaml in Qt create. The compiler uses MinGW32 (not vs)

1. System environment

Here I only describe the environment I used when configuring

  • win11 64 bit
  • Qt 5.14.2
  • yaml-cpp 0.7.0
  • CMake 3.23.2
  • Compiler: MinGW32

(yaml-cpp-master seems to have some problems. It will report an error every time it is compiled. It is recommended to use 0.7.0)

Regarding configuring MinGW32, please see my other article, point 2: Configuring environment variables

2. Download yaml-cpp 0.7.0

Download yaml-cpp from Github
Insert image description here
and unzip it, open the unzipped directory, and create a new buildfolder named inside.
Insert image description here

3、CMake

Open camke-gui

①Select directory:

My path here is:

# Where is the source code:
H:/google_download/yaml-cpp-yaml-cpp-0.7.0

# Where to build the binaries:
H:/google_download/yaml-cpp-yaml-cpp-0.7.0/build

Insert image description here
! ! ! Notice! ! !
The following paths were originally written based on yaml-cpp-master. Please change it to yaml-cpp-yaml-cpp-0.7.0 now.

②Configure option

Click configure
Insert image description here

then select
Insert image description here
Insert image description here

Compilers

# C
D:/software/Qt/Qt5.14.2/Tools/mingw730_64/bin/gcc.exe

# C++
D:/software/Qt/Qt5.14.2/Tools/mingw730_64/bin/g++.exe

Insert image description here
Click Finish and don't worry if it
Insert image description here
appears in red. When you see it, Configuring doneclick Generate to turn off cmake-gui.
Insert image description here
Generating done

4. Compile

buildEnter the folder we just created , and you will see the content output by CMake just now.
Insert image description here
Place the mouse in the folder interface, hold down the shift key, and right-click the mouse at the same time. Click to open the Powershell window(s) here, enter Windows Powershell and enter the following
Insert image description here
command, and press Enter to execute the command.

mingw32-make -j 8

The purpose here -j 8is to allow the CPU to perform multi-tasking and speed up compilation. Make settings according to your computer's configuration.
Wait for the terminal to finish running. . . . . . . . .
Insert image description here
You can buildsee it in the folder libyaml-cpp.a. This is the file we need to use later.
Insert image description here
There is another folder that needs to be used, which is in the yaml-cpp-master directory.include
Insert image description here

5. Test with Qt

①Create a new Qt project

Create a new project in Qt Create and follow the normal process. When selecting kits, be sure to select MinGw 64.
Insert image description here

②Move xxx.a file

libCreate a new folder in the Qt project directory and put
Insert image description here
what we just generated libyaml-cpp.ainto it.
Insert image description here

③Add yaml-cpp

Add the following content to xxx.prothe file
Insert image description here
and modify it according to your actual situation: INCLUDEPATH is the folder
we just mentioned , which is in the yaml-cpp-master directory.includeinclude

INCLUDEPATH += H:\google_download\yaml-cpp-master\include

LIBS += $$PWD/lib/libyaml-cpp.a

Insert image description here

④Execute qmake

Insert image description here
Insert image description here

⑤Test

First prepare a yaml file, test.yamlthe content is:

name: Hunzi
num: 123

Import the header file in mainwindow.cpp

#include "yaml-cpp/yaml.h"
using namespace YAML;

In the constructor write:

Node config;
try{
    
    
    config = LoadFile("H:/TempFiles/test.yaml");
} catch(BadFile &e) {
    
    
    qDebug() <<"read error!";
}
qDebug() << "name:" << QString::fromStdString(config["name"].as<std::string>()) << endl;
qDebug() << "num:" << config["num"].as<int>() << endl;

⑥Check the kit

Insert image description here

⑦Run

Insert image description here

question

If the kit is not chosen by me MingGW 64, for example, if I choose it here, MSVC2017 64
Insert image description here
Insert image description here
you only MingGW 64need to change it back.

At this point, Qt5.14.2 configuration yaml-cpp is completed.

Guess you like

Origin blog.csdn.net/iiinoname/article/details/125344979