在另一篇中写过我将boost 编译成了静态库,在项目中随处引用头文件可以使用,这篇文章介绍另一种使用用boost库的方式步骤如下:
一、拷贝boost源码到使用它的项目中
二、在pro/pri文件中进行头文件声明(INCLUDEPATH += boostPath)
三、在源文件中引用头文件
是不是很快捷。好我们看看测试代码:
#include <QCoreApplication>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <QDebug>
int add(int a, int b) {
return a + b;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
boost::function<int (int, int)> callObj = boost::bind(add, _1, _2);
qDebug() << callObj(34, 66);
return a.exec();
}
得到了正确结果: