1. 下载解压
2. QT.pro添加路径:
CONFIG += c++17
INCLUDEPATH += “D:\boost_1_86_0”
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17
DEFINES += QT_DEPRECATED_WARNINGS
INCLUDEPATH += "D:\boost_1_86_0"
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
注意:LIBS项中的boost路径前面需要加上-L,并且和boost路径之间没有空格。
3. 在QT项目中引入所需的boost头文件:
结构体历遍
#include <QCoreApplication>
#include <boost/pfr.hpp>
#include <QDebug>
struct MyStruct {
int a;
float b;
char c;
};
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
MyStruct ms = {10, 3.14f, 'A'};
boost::pfr::for_each_field(ms, [](const auto& field) {
qDebug() << field;
});
return app.exec();
}