QWT,全称是Qt Widgets for Technical Applications,是一个基于LGPL版权协议的开源项目, 可生成各种统计图。它为具有技术专业背景的程序提供GUI组件和一组实用类,其目标是以基于2D方式的窗体部件来显示数据, 数据源以数值,数组或一组浮点数等方式提供, 输出方式可以是Curves(曲线),Slider(滚动条),Dials(圆盘),Compasses(仪表盘)等等。该工具库基于Qt开发,所以也继承了Qt的跨平台特性。
摘自百度百科
首先到http://sourceforge.net/projects/qwt/files/qwt/下载源码,我选择了6.0.1版本。
下载完,我把qwt-6.0.1.zip解压至c盘下,然后修改qwtconfig.pri
改成:
win32 {
QWT_INSTALL_PREFIX = C:/qwt-6.0.1
}
再改qwtbulid.pri,改成:
win32 {
# On Windows you can't mix release and debug libraries.
# The designer is built in release mode. If you like to use it
# you need a release version. For your own application development you
# might need a debug version.
# Enable debug_and_release + build_all if you want to build both.
#CONFIG += debug_and_release
CONFIG += build_all
}
接着我没有用Qt 4.7.4 Command Prompt,直接打开qwt.pro,然后编译,最后可能报错,不用管它。
然后,把C:\qwt-6.0.1\lib下dll文件放到C:\Qt\4.7.4\bin下,a文件放到C:\Qt\4.7.4\lib;
再把C:\qwt-6.0.1\designer\plugins\designer下两个文件拷贝到C:\Qt\4.7.4\plugins\designer;
最后C:\qwt-6.0.1\src下所有头文件拷贝至C:\Qt\4.7.4\include\Qwt(Qwt需自己新建)。
测试qwt:
把examples的例子编译了一下,发现qwt真的不错。
然后借前人的例子,试一试:
qwt.pro
QT += core gui
TARGET = qwt
TEMPLATE = app
SOURCES += main.cpp\
Plot.cpp
HEADERS += Plot.h
LIBS += -L "C:/Qt/4.7.4/lib" -lqwt
INCLUDEPATH += C:/Qt/4.7.4/include/Qwt
Plot.h
#ifndef PLOT_H
#define PLOT_H
#include <qapplication.h>
#include <QtGui>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
class Plot : public QwtPlot
{
public:
Plot();
};
#endif PLOT_H
Plot.cpp
#include "plot.h"
Plot::Plot()
{
setTitle("A Simple QwtPlot Demonstration");//设置标题
insertLegend(new QwtLegend(), QwtPlot::RightLegend);//设置标线的栏
setAxisTitle(xBottom, "x -->");
setAxisScale(xBottom, 0.0, 10.0);
setAxisTitle(yLeft, "y -->");
setAxisScale(yLeft, 0, 10.0);
QwtPlotCurve *curve = new QwtPlotCurve("line1");//实例化一条曲线
curve->attach(this);
double *x=new double[5];
double *y=new double[5];
for(int i=0;i<5;i++)
{
x[i]=i;
y[i]=i+3;
}
curve->setSamples (x,y,5);//传画曲线的数据
curve->setPen(QPen(Qt::red));
QwtPlotCurve *curve2 = new QwtPlotCurve("line2");//实例化另一条线
curve2->attach(this);
double *x2=new double[5];
double *y2=new double[5];
for(int i=0;i<5;i++)
{
x2[i]=i*3;
y2[i]=i+3;
}
curve2->setSamples (x2,y2,5);
curve2->setPen(QPen(Qt::green));
}
main.cpp
#include <QtGui>
#include "plot.h"
int main(int argc,char *argv[])
{
QApplication *app;
app=new QApplication(argc,argv);
Plot winmain;
winmain.show();
return app->exec();
}
(只能发布,不能调试o_o!!!)