qwt的安装(绝对正确)

来源:互联网 发布:单片机交通灯设计c 编辑:程序博客网 时间:2024/05/16 02:29

主要参考:

http://www.qtcentre.org/threads/53787-HowTo-Installation-of-Qt-5-0-1-and-Qwt-6-1-0-rc3-(Win7-64bit)

http://blog.chinaunix.net/uid-26312142-id-3372860.html

http://blog.sina.com.cn/s/blog_4888f8810100y55l.html

http://qt-project.org/forums/viewthread/7597/P15


官方安装指导

http://qwt.sourceforge.net/qwtinstall.html

官方下载地址(要翻墙)

http://sourceforge.net/projects/qwt/files/

里面有windows版的creator plugin插件,有压缩好的帮助文件


---------------------------------

网上写的东西有些是正确的,有些是错误的,要亲自实践才知道有无问题


1. 首先下载好qwt的包,在这里的版本是qwt-6.1-rc3

2. 搭建好qt开发环境,就是需要qt creator&sdk等等,主要是需要 Qt 5.0.1 for Desktop (MinGW 4.7) 这个命令行环境

3. 将qwt-6.1-rc3解压到任意地方,如d:\Qt\qwt-6.1-rc3

4. 然后在开始菜单找到Qt 5.0.1 for Desktop (MinGW 4.7) 这个命令行环境,cd到d:\Qt\qwt-6.1-rc3(源码根目录)

5. 配置编译参数,相关文件有:qwt.pro,qwtbuild.pri,qwtconfig.pri,qwtfunctions.pri。(相关语法可以参考我的另一篇文章)需要特别注意是修改qwt编译好后安装路径。修改qwtconfig.pri,windows就是win32,linux就是unix,下面是windows下,修改qwt安装目录的操作:

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. win32 {  
  2. #QWT_INSTALL_PREFIX    = C:/Qwt-$$QWT_VERSION-rc3  
  3. # make a dir "setup" for intalling  
  4. QWT_INSTALL_PREFIX    = D:/Qt/qwt-6.1-rc3/setup  
  5. }  

上面的意思就是将编译好的东西拷贝到D:/Qt/qwt-6.1-rc3/setup下面。

6. 在Qt 5.0.1 for Desktop (MinGW 4.7) 这个命令行环境执行:

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. // 没有考虑使用vs的nmake,直接使用默认的mingw编译  
  2.   
  3. qmake  
  4.   
  5. // 编译  
  6. mingw32-make  
  7.   
  8. // 安装到配置指定目录,其实这一步可以跳过  
  9. mingw32-make install  

编译&安装好后,D:/Qt/qwt-6.1-rc3/setup目录下面的东西有:

doc,features,include就是直接从源码包考过来的,编译的有lib和plugins,lib是库,plugins是Qt Designer的插件

* 编译出来的东西与qt的目录结构完全对应(mingw下面的目录)

* 如果要在creator中使用qt designer插件,在windows下qwt不能是debug版和release版混合编译,只使用release版!!

* 并且creator和qwt必须采用同一种编译器源码编译而来,在windows下采用(mingw或者vs的nmake)

参考http://www.qtcentre.org/threads/32239-Qwt-plugins-in-Qt-Creator

抽空将更新编译creator实现qwt插件使用(下面是用于编译可以在creator中使用的qwt插件,不需要qwt可以跳过)

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. qmake.exe qwt.pro -spec win32-g++ -r CONFIG+=release  

7. 添加环境变量D:\Qt\Qwt-6.1.0-rc3\setup\lib到path系统变量(不需要该步骤了),添加QT_PLUGIN_PATH变量指向上图D:/Qt/qwt-6.1-rc3/setup/plugins目录,添加QMAKEFEATURES变量指向上图D:/Qt/qwt-6.1-rc3/setup/features(修改了系统变量,记得重启下qt creator或者命令行)


8. 在使用qwt时,在pro文件里面添加CONFIG += qwt一行就可以了。

网上另一种方法添加:

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. // 指向编译好的lib库  
  2. LIBS += -L"c:/Qt/2010.05/qt/lib" -lqwt  
  3. // 指向源码文件,头文件#include <qwt_plot.h>使用  
  4. INCLUDEPATH += c:/Qt/2010.05/qt/include/qwt  

9. 最后可以跑下测试代码,看是否安装完成,这个是example里面的代码

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #include <qapplication.h>  
  2. #include <qwt_plot.h>  
  3. #include <qwt_plot_curve.h>  
  4. #include <qwt_plot_grid.h>  
  5. #include <qwt_symbol.h>  
  6. #include <qwt_legend.h>  
  7.   
  8. int main( int argc, char **argv )  
  9. {  
  10.     QApplication a( argc, argv );  
  11.   
  12.     QwtPlot plot;  
  13.     plot.setTitle( "Plot Demo" );  
  14.     plot.setCanvasBackground( Qt::white );  
  15.     plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );  
  16.     plot.insertLegend( new QwtLegend() );  
  17.   
  18.     QwtPlotGrid *grid = new QwtPlotGrid();  
  19.     grid->attach( &plot );  
  20.   
  21.     QwtPlotCurve *curve = new QwtPlotCurve();  
  22.     curve->setTitle( "Some Points" );  
  23.     curve->setPen( Qt::blue, 4 ),  
  24.     curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );  
  25.   
  26.     QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,  
  27.         QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );  
  28.     curve->setSymbol( symbol );  
  29.   
  30.     QPolygonF points;  
  31.     points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )  
  32.         << QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )  
  33.         << QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );  
  34.     curve->setSamples( points );  
  35.   
  36.     curve->attach( &plot );  
  37.   
  38.     plot.resize( 600, 400 );  
  39.     plot.show();  
  40.   
  41.     return a.exec();  
  42. }  

-------------------------------------------------------

以下更新在ubuntu下安装Qt5


--------------第一步,搭建qt环境---------------

1. 从qt官网上下载qt-linux-opensource-5.0.2-x86_64-offline.run这个包。给予可执行权限。(右键添加或者chmod +x),双击运行安装,我安装到了/home/tangtao/Qt5.0.2/

2. 需要安装很多包(不同环境安装不同的包。要自己考察)

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. //安装gcc  
  2. sudo apt-get install build-essential  
  3. //安装openGL包  
  4. sudo apt-get install libglu1-mesa  
  5. sudo apt-get install libgl1-mesa-dev  
  6. sudo apt-get install freeglut3-dev  


* 新版的qt(linux版)已经没有qt assisant和qt designer,编译出来的designer插件没用了

* sudo apt-get install libqt4-dev 或者 sudo apt-get install qt5-default, qtbase5-dev 都不行,要与creator中的qmake对应,因此可能要在PATH里面添加qmake路径

* 如果使用了不同版本的qmake编译出来的库需要更新,不然creator中会报错(库指针有问题)


--------------第二步,编译安装qwt---------------

步骤与windows相同。注意修改安装路径

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. //ubuntu采用gcc作为编译器,不再是mingw  
  2. qmake  
  3. make  
  4. sudo make install  

拷贝源码到/home/tangtao/Qt5.0.2/5.0.2/gcc_64/include/qwt

拷贝库到/home/tangtao/Qt5.0.2/5.0.2/gcc_64/lib

相应的doc也可以拷贝到gcc_64/doc下面


* 编译出来的东西与qt的目录结构完全对应


添加运行环境设置:为了编译出来的程序运行时能够顺利调用,需要在/etc/profile 里建立环境变量 LD_LIBRARY_PATH变量。(与windows类似)

0 0