Results 1 to 7 of 7

Thread: I cannot use Qwt

  1. #1
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default I cannot use Qwt

    Hello, Everyone!

    I installed qwt-6.0.2:

    qmake
    mingw32-make

    With the file 'qwtconfig.pri':

    Qt Code:
    1. ################################################################
    2. # Qwt Widget Library
    3. # Copyright (C) 1997 Josef Wilgen
    4. # Copyright (C) 2002 Uwe Rathmann
    5. #
    6. # This library is free software; you can redistribute it and/or
    7. # modify it under the terms of the Qwt License, Version 1.0
    8. ################################################################
    9.  
    10. QWT_VER_MAJ = 6
    11. QWT_VER_MIN = 0
    12. QWT_VER_PAT = 2
    13. QWT_VERSION = $${QWT_VER_MAJ}.$${QWT_VER_MIN}.$${QWT_VER_PAT}
    14.  
    15. ######################################################################
    16. # Install paths
    17. ######################################################################
    18.  
    19. QWT_INSTALL_PREFIX = $$[QT_INSTALL_PREFIX]
    20.  
    21. unix {
    22. QWT_INSTALL_PREFIX = /usr/local/qwt-$$QWT_VERSION
    23. }
    24.  
    25. win32 {
    26. QWT_INSTALL_PREFIX = C:/Qwt-$$QWT_VERSION
    27. }
    28.  
    29. QWT_INSTALL_DOCS = $${QWT_INSTALL_PREFIX}/doc
    30. QWT_INSTALL_HEADERS = $${QWT_INSTALL_PREFIX}/include
    31. QWT_INSTALL_LIBS = $${QWT_INSTALL_PREFIX}/lib
    32.  
    33. ######################################################################
    34. # Designer plugin
    35. ######################################################################
    36.  
    37. QWT_INSTALL_PLUGINS = $${QWT_INSTALL_PREFIX}/plugins/designer
    38. # QWT_INSTALL_PLUGINS = $${QT_INSTALL_PREFIX}/plugins/designer
    39.  
    40. ######################################################################
    41. # Features
    42. # When building a Qwt application with qmake you might want to load
    43. # the compiler/linker flags, that are required to build a Qwt application
    44. # from qwt.prf. Therefore all you need to do is to add "CONFIG += qwt"
    45. # to your project file and take care, that qwt.prf can be found by qmake.
    46. # ( see http://doc.trolltech.com/4.7/qmake-advanced-usage.html#adding-new-configuration-features )
    47. # I recommend not to install the Qwt features together with the
    48. # Qt features, because you will have to reinstall the Qwt features,
    49. # with every Qt upgrade.
    50. ######################################################################
    51.  
    52. QWT_INSTALL_FEATURES = $${QWT_INSTALL_PREFIX}/features
    53. # QWT_INSTALL_FEATURES = $${QT_INSTALL_PREFIX}/features
    54.  
    55. ######################################################################
    56. # qmake internal options
    57. ######################################################################
    58.  
    59. CONFIG += qt # Also for Qtopia Core!
    60. CONFIG += warn_on
    61. CONFIG += thread
    62. CONFIG += silent
    63.  
    64. win32 {
    65. # On Windows you can't mix release and debug libraries.
    66. # The designer is built in release mode. If you like to use it
    67. # you need a release version. For your own application development you
    68. # might need a debug version.
    69. # Enable debug_and_release + build_all if you want to build both.
    70.  
    71. #CONFIG += release # release/debug/debug_and_release
    72. CONFIG += debug_and_release
    73. #CONFIG += build_all
    74. }
    75.  
    76. ######################################################################
    77. # Build the static/shared libraries.
    78. # If QwtDll is enabled, a shared library is built, otherwise
    79. # it will be a static library.
    80. ######################################################################
    81.  
    82. #QWT_CONFIG += QwtDll
    83.  
    84. ######################################################################
    85. # QwtPlot enables all classes, that are needed to use the QwtPlot
    86. # widget.
    87. ######################################################################
    88.  
    89. QWT_CONFIG += QwtPlot
    90.  
    91. ######################################################################
    92. # QwtWidgets enables all classes, that are needed to use the all other
    93. # widgets (sliders, dials, ...), beside QwtPlot.
    94. ######################################################################
    95.  
    96. QWT_CONFIG += QwtWidgets
    97.  
    98. ######################################################################
    99. # If you want to display svg images on the plot canvas, or
    100. # export a plot to a SVG document
    101. ######################################################################
    102.  
    103. QWT_CONFIG += QwtSvg
    104.  
    105. ######################################################################
    106. # You can use the MathML renderer of the Qt solutions package to
    107. # enable MathML support in Qwt. Because of license implications
    108. # the ( modified ) code of the MML Widget solution is included and
    109. # linked together with the QwtMathMLTextEngine into an own library.
    110. # To use it you will have to add "CONFIG += qwtmathml"
    111. # to your qmake project file.
    112. ######################################################################
    113.  
    114. QWT_CONFIG += QwtMathML
    115.  
    116. ######################################################################
    117. # If you want to build the Qwt designer plugin,
    118. # enable the line below.
    119. # Otherwise you have to build it from the designer directory.
    120. ######################################################################
    121.  
    122. QWT_CONFIG += QwtDesigner
    123.  
    124. ######################################################################
    125. # If you want to auto build the examples, enable the line below
    126. # Otherwise you have to build them from the examples directory.
    127. ######################################################################
    128.  
    129. # QWT_CONFIG += QwtExamples
    130.  
    131. ######################################################################
    132. # When Qt has been built as framework qmake ( qtAddLibrary ) wants
    133. # to link frameworks instead of regular libs
    134. ######################################################################
    135.  
    136. macx:CONFIG(qt_framework, qt_framework|qt_no_framework) {
    137.  
    138. QWT_CONFIG += QwtFramework
    139. }
    To copy to clipboard, switch view to plain text mode 

    I went in the directory 'c:\qt\qwt-6.0.2\examples\bode\'

    And I changed the file 'bode.pro':

    Qt Code:
    1. ################################################################
    2. # Qwt Widget Library
    3. # Copyright (C) 1997 Josef Wilgen
    4. # Copyright (C) 2002 Uwe Rathmann
    5. #
    6. # This library is free software; you can redistribute it and/or
    7. # modify it under the terms of the Qwt License, Version 1.0
    8. ################################################################
    9.  
    10. include( $${PWD}/../examples.pri )
    11.  
    12. TARGET = bode
    13.  
    14. HEADERS = \
    15. mainwindow.h \
    16. plot.h \
    17. complexnumber.h \
    18. pixmaps.h
    19.  
    20. SOURCES = \
    21. plot.cpp \
    22. mainwindow.cpp \
    23. main.cpp
    24.  
    25. QWT_LOCATION = c:\qt\qwt-6.0.2
    26. INCLUDEPATH += $${QWT_LOCATION}/src
    27. LIBS = -L$${QWT_LOCATION}/lib \
    28. -lqwt
    29.  
    30. if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
    31. win32:LIBS = $$member(LIBS, 0) \
    32. $$member(LIBS, 1)d
    33. }
    To copy to clipboard, switch view to plain text mode 

    I wrote two commands:

    qmake -o Makefile bode.pro
    mingw32-make

    I saw the file with the extension '.o'. But I did not see the file 'bode.exe'

    Output:
    Qt Code:
    1. C:\qt\qwt-6.0.2\examples\bode>qmake -o Makefile bode.pro
    2. WARNING: c:\qt\qwt-6.0.2\examples\bode\bode.pro:25: Unescaped backslashes are deprecated.
    3. WARNING: c:\qt\qwt-6.0.2\examples\bode\bode.pro:25: Unescaped backslashes are deprecated.
    4. WARNING: c:\qt\qwt-6.0.2\examples\bode\bode.pro:25: Unescaped backslashes are deprecated.
    5.  
    6. C:\qt\qwt-6.0.2\examples\bode>mingw32-make
    7. C:/MinGW/bin/mingw32-make.EXE -f Makefile.Debug all
    8. mingw32-make.EXE[1]: Entering directory `C:/qt/qwt-6.0.2/examples/bode'
    9. compiling plot.cpp
    10. compiling mainwindow.cpp
    11. compiling main.cpp
    12. moc mainwindow.h
    13. compiling moc/moc_mainwindow.cpp
    14. moc plot.h
    15. compiling moc/moc_plot.cpp
    16. linking ..\bin\bode.exe
    17. mingw32-make.EXE[1]: Leaving directory `C:/qt/qwt-6.0.2/examples/bode'
    18. C:/MinGW/bin/mingw32-make.EXE -f Makefile.Release all
    19. mingw32-make.EXE[1]: Entering directory `C:/qt/qwt-6.0.2/examples/bode'
    20. compiling plot.cpp
    21. compiling mainwindow.cpp
    22. compiling main.cpp
    23. compiling moc/moc_mainwindow.cpp
    24. compiling moc/moc_plot.cpp
    25. linking ..\bin\bode.exe
    26. mingw32-make.EXE[1]: Leaving directory `C:/qt/qwt-6.0.2/examples/bode'
    To copy to clipboard, switch view to plain text mode 

    Thanks!

    Ivan

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I cannot use Qwt

    Quote Originally Posted by 8Observer8 View Post
    I installed qwt-6.0.2:
    All you did is to build Qwt, it is not installed !.

    A proper installation always ends with:
    Qt Code:
    1. mingw32-make install
    To copy to clipboard, switch view to plain text mode 
    The project files for building the Qwt examples are completely different to the project files of an application. Better throw away what you did so far.


    • When you want to check the examples use the project files as they are. All you need to do is to set the PATH variable, so that the lib and examples/bin directories ( read the line "linking" in the output you have posted ) are found.
    • For building an application configure qmake, so that it finds qwt.prf where you have Qwt installed: see https://qt-project.org/doc/qt-4.8/qm...ation-features.

      I prefer to use option 2 using the QMAKEFEATURES property:
      Qt Code:
      1. qmake -set QMAKEFEATURES "C:/Qwt-6.0/features:..."
      To copy to clipboard, switch view to plain text mode 

      Then simply add the following line to your project file:
      Qt Code:
      1. CONFIG += qwt
      To copy to clipboard, switch view to plain text mode 


    When it is a new project I recommend to start with Qwt 6.1.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    8Observer8 (8th January 2013)

  4. #3
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: I cannot use Qwt

    Thank you very much!

    Yes, I found the file 'bode.exe' in the directory 'C:\qt\qwt-6.0.2\examples\bin'

    What will be happened when I will install the Qwt? I can get the file '.exe' without the installation of the Qwt (without: mingw32-make install)

    Your reply is very useful for me. I am studying the documentation of the qmake now.

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I cannot use Qwt

    Quote Originally Posted by 8Observer8 View Post
    What will be happened when I will install the Qwt?
    No reason for being afraid of something - your system won't be modified in any way beside that Qwt copies some files in a proper way below the directory you have configured in qwtconfig.pri. After removing the directory your system is in the same state as before.

    Running into problems because of not doing this step makes absolutely no sense.

    Uwe

  6. The following user says thank you to Uwe for this useful post:

    8Observer8 (8th January 2013)

  7. #5
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: I cannot use Qwt

    Thanks!

    Ivan

  8. #6
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: I cannot use the Qwt on Qt Creator

    Hello again!

    I build the project:

    bode.pro

    Qt Code:
    1. ################################################################
    2. # Qwt Widget Library
    3. # Copyright (C) 1997 Josef Wilgen
    4. # Copyright (C) 2002 Uwe Rathmann
    5. #
    6. # This library is free software; you can redistribute it and/or
    7. # modify it under the terms of the Qwt License, Version 1.0
    8. ################################################################
    9.  
    10.  
    11.  
    12. TARGET = bode
    13.  
    14. HEADERS = \
    15. mainwindow.h \
    16. plot.h \
    17. complexnumber.h \
    18. pixmaps.h
    19.  
    20. SOURCES = \
    21. plot.cpp \
    22. mainwindow.cpp \
    23. main.cpp
    24.  
    25. QWT_LOCATION = c:/Qwt-6.0.2
    26. INCLUDEPATH += $${QWT_LOCATION}/include
    27. LIBS = -L$${QWT_LOCATION}/lib \
    28. -lqwt
    29.  
    30. if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
    31. win32:LIBS = $$member(LIBS, 0) \
    32. $$member(LIBS, 1)d
    33. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp

    Qt Code:
    1. #include <qapplication.h>
    2. #include "mainwindow.h"
    3.  
    4. int main ( int argc, char **argv )
    5. {
    6. QApplication a( argc, argv );
    7.  
    8. MainWindow w;
    9. w.resize( 540, 400 );
    10. w.show();
    11.  
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #include <qmainwindow.h>
    2.  
    3. class Plot;
    4. class QPolygon;
    5.  
    6. class MainWindow : public QMainWindow
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. MainWindow( QWidget *parent = 0 );
    12.  
    13. private Q_SLOTS:
    14. void moved( const QPoint & );
    15. void selected( const QPolygon & );
    16.  
    17. #ifndef QT_NO_PRINTER
    18. void print();
    19. #endif
    20.  
    21. void exportDocument();
    22. void enableZoomMode( bool );
    23.  
    24. private:
    25. void showInfo( QString text = QString::null );
    26.  
    27. Plot *d_plot;
    28.  
    29. QwtPlotZoomer *d_zoomer[2];
    30. QwtPlotPicker *d_picker;
    31. QwtPlotPanner *d_panner;
    32. };
    To copy to clipboard, switch view to plain text mode 

    mainwindow.cpp
    Qt Code:
    1. #include <qregexp.h>
    2. #include <qtoolbar.h>
    3. #include <qtoolbutton.h>
    4. #include <qlabel.h>
    5. #include <qlayout.h>
    6. #include <qstatusbar.h>
    7. #include <qprinter.h>
    8. #include <qpicture.h>
    9. #include <qpainter.h>
    10. #include <qfiledialog.h>
    11. #include <qimagewriter.h>
    12. #include <qprintdialog.h>
    13. #include <qfileinfo.h>
    14. #include <qwt_counter.h>
    15. #include <qwt_picker_machine.h>
    16. #include <qwt_plot_zoomer.h>
    17. #include <qwt_plot_panner.h>
    18. #include <qwt_plot_renderer.h>
    19. #include <qwt_text.h>
    20. #include <qwt_math.h>
    21. #include "pixmaps.h"
    22. #include "plot.h"
    23. #include "mainwindow.h"
    24.  
    25. class Zoomer: public QwtPlotZoomer
    26. {
    27. public:
    28. Zoomer( int xAxis, int yAxis, QwtPlotCanvas *canvas ):
    29. QwtPlotZoomer( xAxis, yAxis, canvas )
    30. {
    31. setTrackerMode( QwtPicker::AlwaysOff );
    32. setRubberBand( QwtPicker::NoRubberBand );
    33.  
    34. // RightButton: zoom out by 1
    35. // Ctrl+RightButton: zoom out to full size
    36.  
    37. setMousePattern( QwtEventPattern::MouseSelect2,
    38. Qt::RightButton, Qt::ControlModifier );
    39. setMousePattern( QwtEventPattern::MouseSelect3,
    40. Qt::RightButton );
    41. }
    42. };
    43.  
    44. //-----------------------------------------------------------------
    45. //
    46. // bode.cpp -- A demo program featuring QwtPlot and QwtCounter
    47. //
    48. // This example demonstrates the mapping of different curves
    49. // to different axes in a QwtPlot widget. It also shows how to
    50. // display the cursor position and how to implement zooming.
    51. //
    52. //-----------------------------------------------------------------
    53.  
    54. MainWindow::MainWindow( QWidget *parent ):
    55. QMainWindow( parent )
    56. {
    57. d_plot = new Plot( this );
    58.  
    59. const int margin = 5;
    60. d_plot->setContentsMargins( margin, margin, margin, 0 );
    61.  
    62. setContextMenuPolicy( Qt::NoContextMenu );
    63.  
    64. d_zoomer[0] = new Zoomer( QwtPlot::xBottom, QwtPlot::yLeft,
    65. d_plot->canvas() );
    66. d_zoomer[0]->setRubberBand( QwtPicker::RectRubberBand );
    67. d_zoomer[0]->setRubberBandPen( QColor( Qt::green ) );
    68. d_zoomer[0]->setTrackerMode( QwtPicker::ActiveOnly );
    69. d_zoomer[0]->setTrackerPen( QColor( Qt::white ) );
    70.  
    71. d_zoomer[1] = new Zoomer( QwtPlot::xTop, QwtPlot::yRight,
    72. d_plot->canvas() );
    73.  
    74. d_panner = new QwtPlotPanner( d_plot->canvas() );
    75. d_panner->setMouseButton( Qt::MidButton );
    76.  
    77. d_picker = new QwtPlotPicker( QwtPlot::xBottom, QwtPlot::yLeft,
    78. QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn,
    79. d_plot->canvas() );
    80. d_picker->setStateMachine( new QwtPickerDragPointMachine() );
    81. d_picker->setRubberBandPen( QColor( Qt::green ) );
    82. d_picker->setRubberBand( QwtPicker::CrossRubberBand );
    83. d_picker->setTrackerPen( QColor( Qt::white ) );
    84.  
    85. setCentralWidget( d_plot );
    86.  
    87. QToolBar *toolBar = new QToolBar( this );
    88.  
    89. QToolButton *btnZoom = new QToolButton( toolBar );
    90. btnZoom->setText( "Zoom" );
    91. btnZoom->setIcon( QPixmap( zoom_xpm ) );
    92. btnZoom->setCheckable( true );
    93. btnZoom->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
    94. toolBar->addWidget( btnZoom );
    95. connect( btnZoom, SIGNAL( toggled( bool ) ), SLOT( enableZoomMode( bool ) ) );
    96.  
    97. #ifndef QT_NO_PRINTER
    98. QToolButton *btnPrint = new QToolButton( toolBar );
    99. btnPrint->setText( "Print" );
    100. btnPrint->setIcon( QPixmap( print_xpm ) );
    101. btnPrint->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
    102. toolBar->addWidget( btnPrint );
    103. connect( btnPrint, SIGNAL( clicked() ), SLOT( print() ) );
    104. #endif
    105.  
    106. QToolButton *btnExport = new QToolButton( toolBar );
    107. btnExport->setText( "Export" );
    108. btnExport->setIcon( QPixmap( print_xpm ) );
    109. btnExport->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );
    110. toolBar->addWidget( btnExport );
    111. connect( btnExport, SIGNAL( clicked() ), SLOT( exportDocument() ) );
    112.  
    113. toolBar->addSeparator();
    114.  
    115. QWidget *hBox = new QWidget( toolBar );
    116.  
    117. QHBoxLayout *layout = new QHBoxLayout( hBox );
    118. layout->setSpacing( 0 );
    119. layout->addWidget( new QWidget( hBox ), 10 ); // spacer
    120. layout->addWidget( new QLabel( "Damping Factor", hBox ), 0 );
    121. layout->addSpacing( 10 );
    122.  
    123. QwtCounter *cntDamp = new QwtCounter( hBox );
    124. cntDamp->setRange( 0.0, 5.0, 0.01 );
    125. cntDamp->setValue( 0.0 );
    126.  
    127. layout->addWidget( cntDamp, 0 );
    128.  
    129. ( void )toolBar->addWidget( hBox );
    130.  
    131. addToolBar( toolBar );
    132. #ifndef QT_NO_STATUSBAR
    133. ( void )statusBar();
    134. #endif
    135.  
    136. enableZoomMode( false );
    137. showInfo();
    138.  
    139. connect( cntDamp, SIGNAL( valueChanged( double ) ),
    140. d_plot, SLOT( setDamp( double ) ) );
    141.  
    142. connect( d_picker, SIGNAL( moved( const QPoint & ) ),
    143. SLOT( moved( const QPoint & ) ) );
    144. connect( d_picker, SIGNAL( selected( const QPolygon & ) ),
    145. SLOT( selected( const QPolygon & ) ) );
    146. }
    147.  
    148. #ifndef QT_NO_PRINTER
    149.  
    150. void MainWindow::print()
    151. {
    152. QPrinter printer( QPrinter::HighResolution );
    153.  
    154. QString docName = d_plot->title().text();
    155. if ( !docName.isEmpty() )
    156. {
    157. docName.replace ( QRegExp ( QString::fromLatin1 ( "\n" ) ), tr ( " -- " ) );
    158. printer.setDocName ( docName );
    159. }
    160.  
    161. printer.setCreator( "Bode example" );
    162. printer.setOrientation( QPrinter::Landscape );
    163.  
    164. QPrintDialog dialog( &printer );
    165. if ( dialog.exec() )
    166. {
    167. QwtPlotRenderer renderer;
    168.  
    169. if ( printer.colorMode() == QPrinter::GrayScale )
    170. {
    171. renderer.setDiscardFlag( QwtPlotRenderer::DiscardCanvasBackground );
    172. renderer.setLayoutFlag( QwtPlotRenderer::FrameWithScales );
    173. }
    174.  
    175. renderer.renderTo( d_plot, printer );
    176. }
    177. }
    178.  
    179. #endif
    180.  
    181. void MainWindow::exportDocument()
    182. {
    183. #ifndef QT_NO_PRINTER
    184. QString fileName = "bode.pdf";
    185. #else
    186. QString fileName = "bode.png";
    187. #endif
    188.  
    189. #ifndef QT_NO_FILEDIALOG
    190. const QList<QByteArray> imageFormats =
    191. QImageWriter::supportedImageFormats();
    192.  
    193. QStringList filter;
    194. filter += "PDF Documents (*.pdf)";
    195. #ifndef QWT_NO_SVG
    196. filter += "SVG Documents (*.svg)";
    197. #endif
    198. filter += "Postscript Documents (*.ps)";
    199.  
    200. if ( imageFormats.size() > 0 )
    201. {
    202. QString imageFilter( "Images (" );
    203. for ( int i = 0; i < imageFormats.size(); i++ )
    204. {
    205. if ( i > 0 )
    206. imageFilter += " ";
    207. imageFilter += "*.";
    208. imageFilter += imageFormats[i];
    209. }
    210. imageFilter += ")";
    211.  
    212. filter += imageFilter;
    213. }
    214.  
    215. fileName = QFileDialog::getSaveFileName(
    216. this, "Export File Name", fileName,
    217. filter.join( ";;" ), NULL, QFileDialog::DontConfirmOverwrite );
    218. #endif
    219.  
    220. if ( !fileName.isEmpty() )
    221. {
    222. QwtPlotRenderer renderer;
    223.  
    224. // flags to make the document look like the widget
    225. renderer.setDiscardFlag( QwtPlotRenderer::DiscardBackground, false );
    226. renderer.setLayoutFlag( QwtPlotRenderer::KeepFrames, true );
    227.  
    228. renderer.renderDocument( d_plot, fileName, QSizeF( 300, 200 ), 85 );
    229. }
    230. }
    231.  
    232. void MainWindow::enableZoomMode( bool on )
    233. {
    234. d_panner->setEnabled( on );
    235.  
    236. d_zoomer[0]->setEnabled( on );
    237. d_zoomer[0]->zoom( 0 );
    238.  
    239. d_zoomer[1]->setEnabled( on );
    240. d_zoomer[1]->zoom( 0 );
    241.  
    242. d_picker->setEnabled( !on );
    243.  
    244. showInfo();
    245. }
    246.  
    247. void MainWindow::showInfo( QString text )
    248. {
    249. if ( text == QString::null )
    250. {
    251. if ( d_picker->rubberBand() )
    252. text = "Cursor Pos: Press left mouse button in plot region";
    253. else
    254. text = "Zoom: Press mouse button and drag";
    255. }
    256.  
    257. #ifndef QT_NO_STATUSBAR
    258. statusBar()->showMessage( text );
    259. #endif
    260. }
    261.  
    262. void MainWindow::moved( const QPoint &pos )
    263. {
    264. QString info;
    265. info.sprintf( "Freq=%g, Ampl=%g, Phase=%g",
    266. d_plot->invTransform( QwtPlot::xBottom, pos.x() ),
    267. d_plot->invTransform( QwtPlot::yLeft, pos.y() ),
    268. d_plot->invTransform( QwtPlot::yRight, pos.y() )
    269. );
    270. showInfo( info );
    271. }
    272.  
    273. void MainWindow::selected( const QPolygon & )
    274. {
    275. showInfo();
    276. }
    To copy to clipboard, switch view to plain text mode 

    plot.h
    Qt Code:
    1. #ifndef _PLOT_H_
    2. #define _PLOT_H_
    3.  
    4. #include <qwt_plot.h>
    5.  
    6.  
    7. class Plot: public QwtPlot
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. Plot( QWidget *parent );
    13.  
    14. public Q_SLOTS:
    15. void setDamp( double damping );
    16.  
    17. private:
    18. void showData( const double *frequency, const double *amplitude,
    19. const double *phase, int count );
    20. void showPeak( double freq, double amplitude );
    21. void show3dB( double freq );
    22.  
    23. QwtPlotCurve *d_curve1;
    24. QwtPlotCurve *d_curve2;
    25. QwtPlotMarker *d_marker1;
    26. QwtPlotMarker *d_marker2;
    27. };
    28.  
    29. #endif
    To copy to clipboard, switch view to plain text mode 

    plot.cpp
    Qt Code:
    1. #include <qwt_math.h>
    2. #include <qwt_scale_engine.h>
    3. #include <qwt_symbol.h>
    4. #include <qwt_plot_grid.h>
    5. #include <qwt_plot_marker.h>
    6. #include <qwt_plot_curve.h>
    7. #include <qwt_legend.h>
    8. #include <qwt_text.h>
    9. #include <qmath.h>
    10. #include "complexnumber.h"
    11. #include "plot.h"
    12.  
    13. #if QT_VERSION < 0x040601
    14. #define qExp(x) ::exp(x)
    15. #define qAtan2(y, x) ::atan2(y, x)
    16. #endif
    17.  
    18. static void logSpace( double *array, int size, double xmin, double xmax )
    19. {
    20. if ( ( xmin <= 0.0 ) || ( xmax <= 0.0 ) || ( size <= 0 ) )
    21. return;
    22.  
    23. const int imax = size - 1;
    24.  
    25. array[0] = xmin;
    26. array[imax] = xmax;
    27.  
    28. const double lxmin = log( xmin );
    29. const double lxmax = log( xmax );
    30. const double lstep = ( lxmax - lxmin ) / double( imax );
    31.  
    32. for ( int i = 1; i < imax; i++ )
    33. array[i] = qExp( lxmin + double( i ) * lstep );
    34. }
    35.  
    36. Plot::Plot( QWidget *parent ):
    37. QwtPlot( parent )
    38. {
    39. setAutoReplot( false );
    40.  
    41. setTitle( "Frequency Response of a Second-Order System" );
    42.  
    43. setCanvasBackground( QColor( Qt::darkBlue ) );
    44.  
    45. // legend
    46. QwtLegend *legend = new QwtLegend;
    47. insertLegend( legend, QwtPlot::BottomLegend );
    48.  
    49. // grid
    50. QwtPlotGrid *grid = new QwtPlotGrid;
    51. grid->enableXMin( true );
    52. grid->setMajPen( QPen( Qt::white, 0, Qt::DotLine ) );
    53. grid->setMinPen( QPen( Qt::gray, 0 , Qt::DotLine ) );
    54. grid->attach( this );
    55.  
    56. // axes
    57. enableAxis( QwtPlot::yRight );
    58. setAxisTitle( QwtPlot::xBottom, "Normalized Frequency" );
    59. setAxisTitle( QwtPlot::yLeft, "Amplitude [dB]" );
    60. setAxisTitle( QwtPlot::yRight, "Phase [deg]" );
    61.  
    62. setAxisMaxMajor( QwtPlot::xBottom, 6 );
    63. setAxisMaxMinor( QwtPlot::xBottom, 10 );
    64. setAxisScaleEngine( QwtPlot::xBottom, new QwtLog10ScaleEngine );
    65.  
    66. // curves
    67. d_curve1 = new QwtPlotCurve( "Amplitude" );
    68. d_curve1->setRenderHint( QwtPlotItem::RenderAntialiased );
    69. d_curve1->setPen( QPen( Qt::yellow ) );
    70. d_curve1->setLegendAttribute( QwtPlotCurve::LegendShowLine );
    71. d_curve1->setYAxis( QwtPlot::yLeft );
    72. d_curve1->attach( this );
    73.  
    74. d_curve2 = new QwtPlotCurve( "Phase" );
    75. d_curve2->setRenderHint( QwtPlotItem::RenderAntialiased );
    76. d_curve2->setPen( QPen( Qt::cyan ) );
    77. d_curve2->setLegendAttribute( QwtPlotCurve::LegendShowLine );
    78. d_curve2->setYAxis( QwtPlot::yRight );
    79. d_curve2->attach( this );
    80.  
    81. // marker
    82. d_marker1 = new QwtPlotMarker();
    83. d_marker1->setValue( 0.0, 0.0 );
    84. d_marker1->setLineStyle( QwtPlotMarker::VLine );
    85. d_marker1->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom );
    86. d_marker1->setLinePen( QPen( Qt::green, 0, Qt::DashDotLine ) );
    87. d_marker1->attach( this );
    88.  
    89. d_marker2 = new QwtPlotMarker();
    90. d_marker2->setLineStyle( QwtPlotMarker::HLine );
    91. d_marker2->setLabelAlignment( Qt::AlignRight | Qt::AlignBottom );
    92. d_marker2->setLinePen( QPen( QColor( 200, 150, 0 ), 0, Qt::DashDotLine ) );
    93. d_marker2->setSymbol( new QwtSymbol( QwtSymbol::Diamond,
    94. QColor( Qt::yellow ), QColor( Qt::green ), QSize( 7, 7 ) ) );
    95. d_marker2->attach( this );
    96.  
    97. setDamp( 0.0 );
    98.  
    99. setAutoReplot( true );
    100. }
    101.  
    102. void Plot::showData( const double *frequency, const double *amplitude,
    103. const double *phase, int count )
    104. {
    105. d_curve1->setSamples( frequency, amplitude, count );
    106. d_curve2->setSamples( frequency, phase, count );
    107. }
    108.  
    109. void Plot::showPeak( double freq, double amplitude )
    110. {
    111. QString label;
    112. label.sprintf( "Peak: %.3g dB", amplitude );
    113.  
    114. QwtText text( label );
    115. text.setFont( QFont( "Helvetica", 10, QFont::Bold ) );
    116. text.setColor( QColor( 200, 150, 0 ) );
    117.  
    118. d_marker2->setValue( freq, amplitude );
    119. d_marker2->setLabel( text );
    120. }
    121.  
    122. void Plot::show3dB( double freq )
    123. {
    124. QString label;
    125. label.sprintf( "-3 dB at f = %.3g", freq );
    126.  
    127. QwtText text( label );
    128. text.setFont( QFont( "Helvetica", 10, QFont::Bold ) );
    129. text.setColor( Qt::green );
    130.  
    131. d_marker1->setValue( freq, 0.0 );
    132. d_marker1->setLabel( text );
    133. }
    134.  
    135. //
    136. // re-calculate frequency response
    137. //
    138. void Plot::setDamp( double damping )
    139. {
    140. const bool doReplot = autoReplot();
    141. setAutoReplot( false );
    142.  
    143. const int ArraySize = 200;
    144.  
    145. double frequency[ArraySize];
    146. double amplitude[ArraySize];
    147. double phase[ArraySize];
    148.  
    149. // build frequency vector with logarithmic division
    150. logSpace( frequency, ArraySize, 0.01, 100 );
    151.  
    152. int i3 = 1;
    153. double fmax = 1;
    154. double amax = -1000.0;
    155.  
    156. for ( int i = 0; i < ArraySize; i++ )
    157. {
    158. double f = frequency[i];
    159. const ComplexNumber g =
    160. ComplexNumber( 1.0 ) / ComplexNumber( 1.0 - f * f, 2.0 * damping * f );
    161.  
    162. amplitude[i] = 20.0 * log10( qSqrt( g.real() * g.real() + g.imag() * g.imag() ) );
    163. phase[i] = qAtan2( g.imag(), g.real() ) * ( 180.0 / M_PI );
    164.  
    165. if ( ( i3 <= 1 ) && ( amplitude[i] < -3.0 ) )
    166. i3 = i;
    167. if ( amplitude[i] > amax )
    168. {
    169. amax = amplitude[i];
    170. fmax = frequency[i];
    171. }
    172.  
    173. }
    174.  
    175. double f3 = frequency[i3] - ( frequency[i3] - frequency[i3 - 1] )
    176. / ( amplitude[i3] - amplitude[i3 -1] ) * ( amplitude[i3] + 3 );
    177.  
    178. showPeak( fmax, amax );
    179. show3dB( f3 );
    180. showData( frequency, amplitude, phase, ArraySize );
    181.  
    182. setAutoReplot( doReplot );
    183.  
    184. replot();
    185. }
    To copy to clipboard, switch view to plain text mode 

    pixmaps.h
    Qt Code:
    1. #ifndef PIXMAPS_H
    2. #define PIXMAPS_H
    3.  
    4. static const char *print_xpm[] =
    5. {
    6. "32 32 12 1",
    7. "a c #ffffff",
    8. "h c #ffff00",
    9. "c c #ffffff",
    10. "f c #dcdcdc",
    11. "b c #c0c0c0",
    12. "j c #a0a0a4",
    13. "e c #808080",
    14. "g c #808000",
    15. "d c #585858",
    16. "i c #00ff00",
    17. "# c #000000",
    18. ". c None",
    19. "................................",
    20. "................................",
    21. "...........###..................",
    22. "..........#abb###...............",
    23. ".........#aabbbbb###............",
    24. ".........#ddaaabbbbb###.........",
    25. "........#ddddddaaabbbbb###......",
    26. ".......#deffddddddaaabbbbb###...",
    27. "......#deaaabbbddddddaaabbbbb###",
    28. ".....#deaaaaaaabbbddddddaaabbbb#",
    29. "....#deaaabbbaaaa#ddedddfggaaad#",
    30. "...#deaaaaaaaaaa#ddeeeeafgggfdd#",
    31. "..#deaaabbbaaaa#ddeeeeabbbbgfdd#",
    32. ".#deeefaaaaaaa#ddeeeeabbhhbbadd#",
    33. "#aabbbeeefaaa#ddeeeeabbbbbbaddd#",
    34. "#bbaaabbbeee#ddeeeeabbiibbadddd#",
    35. "#bbbbbaaabbbeeeeeeabbbbbbaddddd#",
    36. "#bjbbbbbbaaabbbbeabbbbbbadddddd#",
    37. "#bjjjjbbbbbbaaaeabbbbbbaddddddd#",
    38. "#bjaaajjjbbbbbbaaabbbbadddddddd#",
    39. "#bbbbbaaajjjbbbbbbaaaaddddddddd#",
    40. "#bjbbbbbbaaajjjbbbbbbddddddddd#.",
    41. "#bjjjjbbbbbbaaajjjbbbdddddddd#..",
    42. "#bjaaajjjbbbbbbjaajjbddddddd#...",
    43. "#bbbbbaaajjjbbbjbbaabdddddd#....",
    44. "###bbbbbbaaajjjjbbbbbddddd#.....",
    45. "...###bbbbbbaaajbbbbbdddd#......",
    46. "......###bbbbbbjbbbbbddd#.......",
    47. ".........###bbbbbbbbbdd#........",
    48. "............###bbbbbbd#.........",
    49. "...............###bbb#..........",
    50. "..................###..........."
    51. };
    52.  
    53.  
    54. static const char *zoom_xpm[] =
    55. {
    56. "32 32 8 1",
    57. "# c #000000",
    58. "b c #c0c0c0",
    59. "a c #ffffff",
    60. "e c #585858",
    61. "d c #a0a0a4",
    62. "c c #0000ff",
    63. "f c #00ffff",
    64. ". c None",
    65. "..######################........",
    66. ".#a#baaaaaaaaaaaaaaaaaa#........",
    67. "#aa#baaaaaaaaaaaaaccaca#........",
    68. "####baaaaaaaaaaaaaaaaca####.....",
    69. "#bbbbaaaaaaaaaaaacccaaa#da#.....",
    70. "#aaaaaaaaaaaaaaaacccaca#da#.....",
    71. "#aaaaaaaaaaaaaaaaaccaca#da#.....",
    72. "#aaaaaaaaaabe###ebaaaaa#da#.....",
    73. "#aaaaaaaaa#########aaaa#da#.....",
    74. "#aaaaaaaa###dbbbb###aaa#da#.....",
    75. "#aaaaaaa###aaaaffb###aa#da#.....",
    76. "#aaaaaab##aaccaaafb##ba#da#.....",
    77. "#aaaaaae#daaccaccaad#ea#da#.....",
    78. "#aaaaaa##aaaaaaccaab##a#da#.....",
    79. "#aaaaaa##aacccaaaaab##a#da#.....",
    80. "#aaaaaa##aaccccaccab##a#da#.....",
    81. "#aaaaaae#daccccaccad#ea#da#.....",
    82. "#aaaaaab##aacccaaaa##da#da#.....",
    83. "#aaccacd###aaaaaaa###da#da#.....",
    84. "#aaaaacad###daaad#####a#da#.....",
    85. "#acccaaaad##########da##da#.....",
    86. "#acccacaaadde###edd#eda#da#.....",
    87. "#aaccacaaaabdddddbdd#eda#a#.....",
    88. "#aaaaaaaaaaaaaaaaaadd#eda##.....",
    89. "#aaaaaaaaaaaaaaaaaaadd#eda#.....",
    90. "#aaaaaaaccacaaaaaaaaadd#eda#....",
    91. "#aaaaaaaaaacaaaaaaaaaad##eda#...",
    92. "#aaaaaacccaaaaaaaaaaaaa#d#eda#..",
    93. "########################dd#eda#.",
    94. "...#dddddddddddddddddddddd##eda#",
    95. "...#aaaaaaaaaaaaaaaaaaaaaa#.####",
    96. "...########################..##."
    97. };
    98.  
    99. #endif
    To copy to clipboard, switch view to plain text mode 

    But I get:

    38.png


    Added after 11 minutes:


    Solution:

    in bode.pro

    Qt Code:
    1. include( $${PWD}/../examples.pri )
    To copy to clipboard, switch view to plain text mode 
    Last edited by 8Observer8; 15th January 2013 at 17:54.

  9. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: I cannot use the Qwt on Qt Creator

    The examples are part of the Qwt project and their project files are for building against the the uninstalled files - modifying them to run with the installed version doesn't make much sense.

    For an application using the installed version of Qwt configure qmake ( QMAKESPECS ) and add this line to your project file: "CONFIG += qwt". You can have a look at qwt.prf to see what commands are executed - if you are interested ( in your case "QT *= svg" was missing ! ).

    Copying a project file from somewhere without understanding it won't help you much.

    Uwe

  10. The following user says thank you to Uwe for this useful post:

    8Observer8 (17th January 2013)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.