假设"D:\boost_1_77_0"是boost库所在路径。

1,在QT项目的.pro文件中修改如下两项:

INCLUDEPATH项中加入D:\boost_1_77_0

LIBS项中加入-LD:\boost_1_77_0

注意:LIBS项中的boost路径前面需要加上-L,并且和boost路径之间没有空格。

2,在QT项目中引入所需的boost头文件:

此处以boost::optional为例。

如下所示,第2行和第3行代码引入了optional相关头文件。

 

 1 #include <QCoreApplication>
 2 #include <boost\optional.hpp>
 3 #include <boost\optional\optional_io.hpp>
 4 #include <iostream>
 5 
 6 int main(int argc, char *argv[])
 7 {
 8     QCoreApplication a(argc, argv);
 9 
10     boost::optional<int> nullable_int1 = {1};
11     boost::optional<int> nullable_int2 = boost::none;
12 
13     std::cout << nullable_int1 << std::endl;
14 
15     if(nullable_int2 == boost::none)
16     {
17         std::cout << "null" << std::endl;
18     }
19 
20     return a.exec();
21 }

 

相关文章:

  • 2021-12-06
  • 2021-12-26
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-08-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2022-03-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案