Qwt 6.0.1 / Qt 4.4.1 / VC++ 9.0 / Win XP

I have written a graphics module for the SigLib library (Digital Signal Library from Numerix-DSP) and have encountered a problem with the zooming function. I get a memory access violation in my routine handling the return to the zoom base:
Unhandled exception at 0x1007463a (qwtd.dll) in SigLibGraph.exe: 0xC0000005: Access violation reading location 0xcdcdcded.
Following the fragment of code where the access violation occured:
uint QwtPlotZoomer::zoomRectIndex() const
{
return d_data->zoomRectIndex;
}

d_data seems to have been not initialized, where should I do it?

Qt Code:
  1. // main.cpp
  2. // AW - 14.03.2012
  3.  
  4. #include <QApplication> // Qt library
  5. #include <qwt_plot.h> // Qwt Plot library
  6. #include <qwt_plot_curve.h>
  7. #include <qwt_math.h>
  8. #include <siglib.h> // SigLib DSP library
  9. #include "SigLibGraph.h" // Qt/Qwt SigLib Graphics library
  10.  
  11. int main( int argc, char * argv[] )
  12. {
  13. QApplication app( argc,argv );
  14.  
  15. const unsigned int FFT_LENGTH = 512;
  16. double *pXData = new double[FFT_LENGTH];
  17. double *pResult = new double[FFT_LENGTH];
  18. double *pResult2 = new double[FFT_LENGTH];
  19.  
  20.  
  21. // fill data arrays
  22. for ( unsigned int idx = 0; idx < FFT_LENGTH; idx++ ) {
  23. pXData[idx] = double( idx );
  24. pResult[idx] = sin( M_PI * 0.02 * double( idx ));
  25. pResult2[idx] = cos( M_PI * 0.02 * double( idx ));
  26. }
  27.  
  28. // plot object
  29. Plot2D *myPlot = new Plot2D( "function plot", "time", "amplitude" );
  30. myPlot->attachCurve( pXData, pResult, FFT_LENGTH, "sine" );
  31. myPlot->attachCurve( pXData, pResult2, FFT_LENGTH, "cosine", Qt::cyan );
  32. myPlot->show();
  33.  
  34. return app.exec();
  35. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. /***************************************************************
  2. SigLibGraph.h
  3.  AW - 31.03.2012
  4. ***************************************************************/
  5.  
  6. #ifndef SIGLIBGRAPH_H
  7. #define SIGLIBGRAPH_H
  8.  
  9. #include <siglib.h> // SigLib DSP library
  10. #include <qwt_plot.h> // Qwt library
  11. #include <qwt_plot_grid.h>
  12. #include <qwt_legend.h>
  13. #include <qwt_plot_zoomer.h>
  14.  
  15.  
  16. class Plot2D: public QwtPlot
  17. {
  18. Q_OBJECT
  19.  
  20. public:
  21. Plot2D( QString plotTitle = "",
  22. QString xLabel = "x-axis",
  23. QString yLabel = "y-axis",
  24. QWidget *parent = NULL );
  25.  
  26. void attachCurve( double *xData,
  27. double *yData,
  28. uint dataCount,
  29. QString curveLabel = "",
  30. QColor curveColor = Qt::yellow );
  31.  
  32. void setXAxisScale( double firstValue, double lastValue );
  33. void setYAxisScale( double firstValue, double lastValue );
  34. void setXLogAxis();
  35. void setYLogAxis();
  36. void setBackgroundColor( QColor backgroundColor );
  37.  
  38. public Q_SLOTS:
  39. void autoRescale( QRectF );
  40.  
  41. protected:
  42. virtual void resizeEvent( QResizeEvent * );
  43.  
  44. private:
  45. QwtPlotGrid *grid;
  46. QwtLegend *legend;
  47. QwtPlotZoomer *zoomer;
  48. };
  49.  
  50. #endif // SIGLIBGRAPH_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. /************************************************************
  2. SigLibGraph.cpp
  3. AW - 31.03.2012
  4. ************************************************************/
  5.  
  6. #include <QApplication>
  7. #include <QtDebug>
  8. #include <qpainter.h>
  9. #include <qwt_plot.h>
  10. #include <qwt_scale_engine.h>
  11. #include <qwt_symbol.h>
  12. #include <qwt_plot_grid.h>
  13. #include <qwt_plot_curve.h>
  14. #include <qwt_legend.h>
  15. #include <qwt_text.h>
  16. #include <qwt_picker.h>
  17. #include <qwt_picker_machine.h>
  18. #include <qwt_plot_zoomer.h>
  19. #include <qwt_plot_renderer.h>
  20. #include <qwt_event_pattern.h>
  21. #include <qwt_text.h>
  22. #include "SigLibGraph.h"
  23.  
  24.  
  25. Plot2D::Plot2D( QString plotTitle,
  26. QString xLabel,
  27. QString yLabel,
  28. QWidget *parent ):
  29. QwtPlot( parent )
  30. {
  31. // plot object
  32. setTitle( plotTitle );
  33. setCanvasBackground( QColor( Qt::darkBlue ));
  34.  
  35. // axis
  36. setAxisTitle( QwtPlot::xBottom, xLabel );
  37. setAxisTitle( QwtPlot::yLeft, yLabel );
  38.  
  39. // grid
  40. QwtPlotGrid* grid = new QwtPlotGrid;
  41. grid->enableXMin( true );
  42. grid->setMajPen( QPen( Qt::white, 0, Qt::DotLine ));
  43. grid->setMinPen( QPen( Qt::gray, 0 , Qt::DotLine ));
  44. grid->attach( this );
  45.  
  46. // legend
  47. QwtLegend* legend = new QwtLegend;
  48. insertLegend( legend, QwtPlot::RightLegend );
  49.  
  50. //zoomer
  51. QwtPlotZoomer* zoomer = new QwtPlotZoomer( QwtPlot::xBottom,
  52. QwtPlot::yLeft,
  53. this->canvas() );
  54. zoomer->setRubberBand( QwtPicker::RectRubberBand );
  55. zoomer->setRubberBandPen( QColor( Qt::green ));
  56. zoomer->setTrackerMode( QwtPicker::ActiveOnly );
  57. zoomer->setTrackerPen( QColor( Qt::white ));
  58. // RightButton: zoom out by one step
  59. zoomer->setMousePattern( QwtEventPattern::MouseSelect3,
  60. Qt::RightButton );
  61. // Ctrl+RightButton: zoom out to full size
  62. zoomer->setMousePattern( QwtEventPattern::MouseSelect2,
  63. Qt::RightButton,
  64. Qt::ControlModifier );
  65. // handle zoom base
  66. connect( zoomer,
  67. SIGNAL( zoomed( QRectF )),
  68. SLOT( autoRescale( QRectF )));
  69.  
  70. // resize Widget
  71. resize( 600, 400 );
  72.  
  73. show();
  74. }
  75.  
  76. void Plot2D::autoRescale( QRectF )
  77. {
  78. qDebug("Plot2D::autoRescale called!");
  79. if( zoomer->zoomRectIndex() == 0 ) // autorescale only if you are at base...
  80. {
  81. this->setAxisAutoScale( QwtPlot::xBottom );
  82. this->setAxisAutoScale( QwtPlot::yLeft );
  83. this->updateAxes();
  84. zoomer->setZoomBase( false );
  85. }
  86. }
  87.  
  88. void Plot2D::attachCurve( double *xData,
  89. double *yData,
  90. uint dataCount,
  91. QString curveLabel,
  92. QColor curveColor )
  93. {
  94. // define the curve object
  95. QwtPlotCurve* curve = new QwtPlotCurve;
  96. curve->setSamples( xData, yData, dataCount );
  97. curve->setPen( QPen( curveColor ));
  98. curve->setRenderHint( QwtPlotItem::RenderAntialiased );
  99. curve->setTitle( curveLabel );
  100. // qDebug() << "curveLabel.isEmpty = " << curveLabel.isEmpty();
  101. if ( curveLabel.isEmpty() )
  102. curve->setItemAttribute( QwtPlotItem::Legend, false );
  103. else
  104. curve->setLegendAttribute( QwtPlotCurve::LegendShowLine );
  105. curve->attach( this );
  106. }
  107.  
  108. void Plot2D::setXAxisScale( double firstValue, double lastValue )
  109. {
  110. setAxisScale( xBottom, firstValue, lastValue );
  111. }
  112.  
  113. void Plot2D::setYAxisScale( double firstValue, double lastValue )
  114. {
  115. setAxisScale( yLeft, firstValue, lastValue );
  116. }
  117.  
  118. void Plot2D::setXLogAxis()
  119. {
  120. setAxisScaleEngine( QwtPlot::xBottom, new QwtLog10ScaleEngine );
  121. }
  122.  
  123. void Plot2D::setYLogAxis()
  124. {
  125. setAxisScaleEngine( QwtPlot::yLeft, new QwtLog10ScaleEngine );
  126. }
  127.  
  128. void Plot2D::setBackgroundColor( QColor backgroundColor )
  129. {
  130. setCanvasBackground( backgroundColor );
  131. }
  132.  
  133. void Plot2D::resizeEvent( QResizeEvent *event )
  134. {
  135. QwtPlot::resizeEvent( event );
  136. }
To copy to clipboard, switch view to plain text mode