您的位置:首页 > 编程语言 > Qt开发

windows下配置qwt开发环境

2015-08-19 12:10 489 查看
最近需要用到qwt来对项目中数据进行绘制,所以在网上查了很多关于qwt的安装,结果很多都说的非常的复杂,折腾了大半天终于解决了,写出来和大家分享一下。

在6.1.0以上的版本中,基本上不需要修改它里面的配置文件,唯一需要的就是安装qt的开发环境。

qt开发环境以Qt5.4.0\5.4\msvc2010_opengl为例

下面来详细说下安装步骤:

1.在qt creater中打开qwt.pro

2.build->clean all project

3.rebuild 

编译完成就后会在当前目录下生成一个lib目录。

将lib内的dll文件拷贝到D:\Qt\Qt5.4.0\5.4\msvc2010_opengl\bin目录下

将lib中的lib文件拷贝到D:\Qt\Qt5.4.0\5.4\msvc2010_opengl\lib目录下

然后在D:\Qt\Qt5.4.0\5.4\msvc2010_opengl\include里面创建一个qwt包含目录,把src中包含的头文件拷贝过来。

这样就完成了qwt的开发环境了。

下面就是如何使用

新建一个 qwidget项目,在xxx.pro文件中添加以下代码:

debug模式下:

LIBS += -L"D:\Qt\Qt5.4.0\5.4\msvc2010_opengl\lib" -lqwtd
INCLUDEPATH += D:\Qt\Qt5.4.0\5.4\msvc2010_opengl\include\qwt

realease模式下:

LIBS += -L"D:\Qt\Qt5.4.0\5.4\msvc2010_opengl\lib" -lqwt

INCLUDEPATH += D:\Qt\Qt5.4.0\5.4\msvc2010_opengl\include\qwt


配置库和包含目录就可以使用了。

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include"qwt/qwt_plot_layout.h"
#include"qwt/qwt_plot.h"
#include"qwt/qwt_plot_curve.h"
#include"qwt/qwt_plot_zoomer.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

ui->qwtPlot->setFrameStyle(QFrame::NoFrame);
//ui->qwtPlot->setLineWidth(0);
// ui->qwtPlot->setcanvasLineWidth(2);
//ui->qwtPlot-
QwtPlotLayout * layout =ui->qwtPlot->plotLayout();
layout->setAlignCanvasToScales(true);

// ui->qwtPlot->setCanvasBackground(QColor(29 , 100 , 141));

//设置xy的范围
ui->qwtPlot->setAxisScale(ui->qwtPlot->xBottom , 1 , 75);
ui->qwtPlot->setAxisScale(ui->qwtPlot->yLeft , -1 , 1);

QwtPlotCurve* pCurve = new QwtPlotCurve("bruve1");

QVector<double> xData;
QVector<double> yData;

for(int i=0;i<75;++i)
xData.push_back(i+1);

yData<<1<<0.048634<<0.655211<<0.320122<<0.130912<<0.182503<<0.163217<<0.167857<<0.169706<<0.15244<<0.17136<<0.184516<<0.183185<<0.16788<<0.150819<<0.154223<<0.149134<<0.126398<<0.090325<<-0.017047<<0.184973<<0.113727<<0.072852<<0.054324<<0.04943<<0.036473<<0.042876<<0.048972<<0.04963<<0.052114<<0.056796<<0.060517<<0.07844<<0.066472<<0.079221<<0.06061<<-0.018855<<0.457584<<0.104125<<0.282665<<0.066127<<0.064099<<0.065944<<0.013025<<0.054401<<0.027663<<0.038911<<0.03153<<0.040123<<0.038832<<0.03919<<0.048258<<0.050396<<0.063897<<0.062202<<0.067778<<0.074743<<0.063545<<0.066624<<0.09162<<-0.022548<<0.037526<<0.04687<<0.04425<<0.046449<<0.038345<<0.051492<<0.033624<<0.030668<<0.075395<<-0.016367<<-0.039846<<0.021928<<0<<0;

pCurve->setSamples(xData , yData);

pCurve->attach(ui->qwtPlot);

QPen pen;
pen.setColor(QColor(255 , 0,0));

pCurve->setPen(pen);

pCurve->setRenderHint(QwtPlotItem::RenderAntialiased , true);

QwtPlotZoomer *pZoomer = new QwtPlotZoomer(ui->qwtPlot->canvas());

pZoomer->setRubberBandPen(QPen(Qt::red));

ui->qwtPlot->replot();

}

MainWindow::~MainWindow()
{
delete ui;
}


以上就完成了数据的正常显示。

在最后感谢下给我帮助的博客:
http://blog.chinaunix.net/uid-20717410-id-2939720.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt