一、QCustomPlot介绍
QCustomPlot 是一个基于Qt的画图和数据可视化C++控件,类似的有QChart、Qwt。
以下使用的QCustomPlot版本为2.1.1,QT Creator版本为6.4.3
二、QCustomPlot下载与安装
下载地址
需要下载QCustomPlot.tar.gz和QCustomPlot-sharedlib.tar.gz两个文件。
把QCustomPlot.gz解压后如下:
把QCustomPlot-sharedlib.tar.gz解压后如下:
2.1 直接使用h和c文件
将QCustomPlot中的qcustomplot.c和qcustomplot.h文件直接放进项目内,然后在项目.pro文件中头部QT += core gui 后面添加printsupport,修改后为QT += core gui printsupport。
在需要使用qcustomplot的项目文件中添加头文件qcustomplot.h。
优点:导入快捷,使用方便
缺点:每次编译项目文件时,会编译qcustomplot.c,因为qcustomplot.c很大,导致每次项目编译时速度很慢。
为了提高项目编译速度,可以使用下面的方法。
2.2 编译为动态库然后导入项目
使用QT Creator打开QCustomPlot-sharedlib/sharedlib-compilation中的sharedlib-compilation.pro,代码如下:
如图所示,将首行修改为
QT += core gui printsupport
即添加printsupport。
然后查看末尾两行,即
SOURCES += ../../qcustomplot.cpp
HEADERS += ../../qcustomplot.h
…/…/表示目前.pro文件的上两级目录,此时需要将QCustomPlot文件夹中的qcustomplot.c和qcustomplot.h粘贴到与QCustomPlot-sharedlib同一级的目录,即qcustomplot.c和qcustomplot.h与QCustomPlot-sharedlib文件夹放到同一个文件夹内。
之后编译.pro打开的工程,会在debug和release文件夹内分别生成如下文件
此时打开需要导入qcustomplot的项目文件夹,新建一个qcustomplot文件夹,将sharedlib-compilation工程文件内release中的libqcustomplot2.a和qcustomplot2.dll;debug中的libqcustomplotd2.a和qcustomplotd2.dll;QCustomPlot.tar.gz解压后的qcustomplot.qch、qcustomplot.c和qcustomplot.h放到项目qcustomplot文件夹内,如下图所示:
右键项目->添加库,弹出如下界面:
选择外部库,然后库文件选择项目文件夹qcustomplot内的libqcustomplot2.a;包含路径选择为项目文件夹qcustomplot;平台根据需要选择;链接类型选择为动态。如下为windows平台示例:
点击下一步,点完成。
此时就可以使用qcustomplot库,并且编译速度很快。
To Be Continue。。。