qwt安装使用精华版
今天在使用Qwt时候遇到了一些问题,在大大小小的问题中折腾了大概一天,先记录下来并反思解决问题的方法。
先是按照和下方相似的流程进行dll编译时(从stackoverflow上检索到):
1. Download and install QT 5.0.2 (MinGw) to: "C:\Qt\Qt5.0.2"
2. Download and extract Qwt 6.1 to:"C:\qwt-6.1.0"
3. Add "C:\Qt\Qt5.0.2\5.0.2\mingw47_32\bin" to your systems pathvariable (qmake.exe is located here)
4. Add "C:\Qt\Qt5.0.2\Tools\MinGW\bin" to your systems pathvariable (mingw32-make.exe is located here)
5. Open a command line (cmd) and navigate to: "C:\qwt-6.1.0"
6. Type: "qmake" (This command won't prompt any msg so don'tworry)
7. Type: "mingw32-make" (Compiles the whole project withexamples; this will take a while so be patient)
出现了类似如下的问题:
And it failed during the make process with the following errors:
linking ../lib/qwt.dll
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -lQt5OpenGL
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -lQt5Svg
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -lQt5PrintSupport
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -lQt5Widgets
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -lQt5Concurrent
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -lQt5Gui
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -lQt5Core
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -llibEGL
c:/qt/qt5.0.2/tools/mingw/bin/../lib/gcc/i686-w64-mingw32/4.7.2/../../../../i686
-w64-mingw32/bin/ld.exe: cannot find -llibGLESv2
collect2.exe: error: ld returned 1 exit status
Makefile.Release:320:recipe for target '../lib/qwt.dll' failed
原因是因为忽略了3和4步骤,也就是忘记将相应部分加入到系统变量中(加入到用户变量中也可)。并上述问题全是在linking时候出的问题(注意路径、lib、dll等)
后来按照如下HOWTO教程配置:(HowTo: Installation of Qt 5.0.1 andQwt 6.1.0 rc3 (Win7 64bit))(来源于网络,忘记是哪个了)
Hello everyone,
i was trying to get Qwt running properly on my Windows7 64bit PC. After hoursof trying to find the right way to do this i wrote a step by step install andtest manual.
I would appreciate a comment of Uwe if this is the right way to do it,especially on the systems path and user variables.
@Uwe: I also hope this guide saves you some time explaining people how toinstall qwt.
Lets start:
1. Download and install QT 5.0.1 (MinGw) to: "C:\Qt\Qt5.0.1"
2. Download and extract Qwt 6.1 RC3 to: "C:\qwt-6.1-rc3"
3. Add "C:\Qt\Qt5.0.1\5.0.1\mingw47_32\bin" to your systems pathvariable (qmake.exe is located here)
4. Add "C:\Qt\Qt5.0.1\Tools\MinGW\bin" to your systems path variable(mingw32-make.exe is located here)
5. Open a command line (cmd) and navigate to: "C:\qwt-6.1-rc3"
6. Type: "qmake" (This command won't prompt any msg so don't worry)
7. Type: "mingw32-make" (Compiles the whole project with examples;this will take a while so be patient)
8. Type: "mingw32-make install" (This installs qwt to the directoryset in "C:\qwt-6.1-rc3\qwtconfig.pri"; the default location is"C:/Qwt-$$QWT_VERSION-rc3" -> "C:\Qwt-6.1.0-rc3\")
9. Add "C:\Qwt-6.1.0-rc3\lib" to your systems path variable
10. Add a User variable named "QT_PLUGIN_PATH" with the followingpath "C:\Qwt-6.1.0-rc3\plugins"
11. Add a User variable named "QMAKEFEATURES" with the following path"C:\Qwt-6.1.0-rc3\features"
12. Start Qt Creator
13. Create a new project: File -> New File or Project ... -> Applications-> Qt Gui Application -> Choose
14. Name it "Test"
15. Create the project in the following directory: "C:\workspace"
16. Open file "Test.pro"
17. Add "Config += qwt" at the bottom
18. Open the main.c of the project and delete all its content.
19. Paste the following in the main.c (This is the qwt example"simpleplot"):
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(newQwtLegend()); 17. 18. QwtPlotGrid*grid=newQwtPlotGrid(); 19. grid->attach(&plot); 20. 21. QwtPlotCurve*curve=newQwtPlotCurve(); 22. curve->setTitle("SomePoints"); 23. curve->setPen( Qt::blue,4), 24. curve->setRenderHint(QwtPlotItem::RenderAntialiased,true); 25. 26. QwtSymbol*symbol=newQwtSymbol(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. }
20. Rightclick the project and select "run qmake..."
21. Now run the project. It should compile without errors and run.
Remember this:
For your own projects you now only have to add "Config += qwt" toyour *.pro file to get Qwt running.
I hope this tutorial helps to do your first steps with QT + Qwt.
可是不知道是不是系统是XP的原因,最终失败。
最后还是中规中矩按照网上的大部分人的方法:
先说完整的解决方案:(这里我用的是qt5.1.1不是SDK版本,自己找到相对应的路径即可(都是在C:\Qt\Qt5.1.1\5.1.1\mingw48_32路径下动作))
1.网上下载:http://sourceforge.net/projects/qwt/files/qwt/6.0.1/我下的是6.0.1,把相关的几个都下下来了.
2.解压qwt-6.0.1.zip,用QtCreator打开qwt.pro(注意不是用vs,可以同时安装QtSDK以及Qt4.8.1库,QtVisual Studio Add-in),取消使用影子构建;
3.构建qwt,构建完成后在qwt-6.0.1\lib目录中会生成若干lib文件和dll文件,复制lib文件到C:\Qt\4.8.1\lib中;复制dll文件到C:\Qt\4.8.1\bin目录中.
4.在qwt-6.0.1\designer\plugins\designer中会生成qwt_designer_plugin.dll以及qwt_designer_plugin.lib,把这两个文件复制到C:\Qt\4.8.1\plugins\designer目录中.
5.搜索qwt-6.0.1\src目录下的所有*.h文件,把所有的头文件复制到C:\Qt\4.8.1\include目录下即可.再打开QtDesigner就可以看到对应的控件了.(可新建Qwt文件夹便于管理,也只有这步骤之后才能在designer中看见qwt的控件)。
接下来,使用如下例子验证:
qwt.pro中添加(与你路径相对应)
INCLUDEPATH+=C:/Qt/Qt5.1.1/5.1.1/mingw48_32/include/Qwt
LIBS+=-LC:/Qt/Qt5.1.1/5.1.1/mingw48_32/lib–lqwtd(release的话用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(); }
这样就可以了。
--------------------------------------------14.3.30------------------------------------------------------
反思:这个库应该有相应的README或install相关文件啊,应该首先从这个下手啊,这时候出问题在从网络上找答案。