Qt中使用Boost库——直接使用Boost源码
步骤1:将Boost源码拷贝到需要使用它的项目中,如下图所示:
步骤2:在pro/pri文件中进行头文件声明(INCLUDEPATH += ./boost_1_66_0)
步骤3:在源文件中引用头文件
是不是很快捷。好,我们看看测试代码:
#include <QCoreApplication>
#include <boost/function.hpp>
#include <boost/bind.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();
}
得到了正确结果:100。