zoukankan      html  css  js  c++  java
  • Qt中使用Boost库

    关于boost库的编译,请看https://www.cnblogs.com/HackerArt/p/10539516.html

    网上可以查到很多介绍qt使用库文件的教程,但是大多都没有注意到,qt中支持设置环境变量这个特性。

    这里我拿boost库来举例说明。

    qt creator创建项目,设置boost库文件的引入。

    image

    将编译生成好的lib目录,添加到LIB或者Path,

    boost库头文件不要添加到INCLUDE中,加到这里qt会提示不识别,

    需要将boost库头文件添加到qt的pro配置文件中。

    提示:boost源目录下的boost目录中的文件 就可以作为include头文件,不需要额外生成,

    # Boost 1_69
    # boost头文件目录
    INCLUDEPATH += D:oostinclude

    qt项目中添加测试代码

    #include "MainWindow.h"
    #include "ui_MainWindow.h"
    
    #include <boost/lexical_cast.hpp>
    #include <boost/regex.hpp>
    #include <iostream>
    #include <Windows.h>
    #include <qdebug.h>
    using namespace std;
    
    void TestBoost()
    {
        using boost::lexical_cast;
        int a = lexical_cast<int>("123");
        double b = lexical_cast<double>("123.0123456789");
        string s0 = lexical_cast<string>(a);
        string s1 = lexical_cast<string>(b);
        //cout << "number: " << a << "  " << b << endl;
        //cout << "string: " << s0 << "  " << s1 << endl;
        //OutputDebugStringA(a);
        qDebug() << a << b << endl;
        qDebug() << s0.c_str() << s1.c_str() << endl;
        //OutputDebugStringA(s1);
        int c = 0;
        try {
            c = lexical_cast<int>("abcd");
        }
        catch (boost::bad_lexical_cast& e) {
            //cout << e.what() << endl;
        }
    }
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        TestBoost();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    清理,重新构建(如果没效果执行qmake)打开debugView查看输出
  • 相关阅读:
    ubuntu下如何批量修改文件后缀名
    vanilla
    Ubuntu apt-get 彻底卸载软件包
    Kendall Rank(肯德尔等级)相关系数
    图像质量评估(IQA)
    conda常用命令
    在ubuntu中搜索文件或文件夹的方法
    libstdc++.so.6: version `GLIBCXX_3.4.21' not found
    迅雷磁力链接转BT种子工具
    springboot 集成mybatis plus3
  • 原文地址:https://www.cnblogs.com/HackerArt/p/10540437.html
Copyright © 2011-2022 走看看