Results 1 to 5 of 5

Thread: QwtPlotPicker Subclass Segfaults

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: QwtPlotPicker Subclass Segfaults

    The stack indicates a crash starting with a QwtPlotZoomer - how the code you have shown related to this ?

    Uwe

  2. #2
    Join Date
    Dec 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotPicker Subclass Segfaults

    Hm.. That is a bit wierd. Ok, not sure why I missed that earlier. I removed all the zoomer code, it no longer sefgaults, but now there are NO markers. I am expecting a horizontal and vertical bars to follow the mouse around on the screen with some custom text. Again:


    QwtPlotPicker .cpp and .h
    Qt Code:
    1. class FreqdBmPicker : public QwtPlotPicker {
    2. public:
    3. FreqdBmPicker( QWidget *canvas );
    4. FreqdBmPicker(int xAxis, int yAxis, RubberBand rubberBand, DisplayMode trackerMode, QWidget* canvas);
    5. virtual QwtText trackerTextF( const QPointF & ) const;
    6. };
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QwtText TimeScaleDraw::label(double v) const { //Convert Double date to a string
    2. return QwtText(QDateTime::fromMSecsSinceEpoch((qint64) (v*1000)).toString("yyyy-MM-dd\nHH:mm:ss.zzz"));
    3. }
    4.  
    5. FreqdBmPicker::FreqdBmPicker(int x, int y, RubberBand rb, DisplayMode dm, QWidget* w): QwtPlotPicker(x, y, rb, dm, w) {
    6. setTrackerMode( dm );
    7. setRubberBand( rb );
    8. setStateMachine( new QwtPickerTrackerMachine() );
    9. setTrackerPen(QColor(Qt::cyan));
    10. setRubberBandPen(QColor(Qt::cyan));
    11. qDebug() << isEnabled();
    12. setEnabled(true);
    13. }
    14. FreqdBmPicker::FreqdBmPicker( QWidget *canvas ): QwtPlotPicker( canvas ) {
    15. setTrackerMode( QwtPicker::AlwaysOn );
    16. setRubberBand( QwtPlotPicker::CrossRubberBand );
    17. setStateMachine( new QwtPickerTrackerMachine() );
    18. setTrackerPen(QColor(Qt::cyan));
    19. setRubberBandPen(QColor(Qt::cyan));
    20. qDebug() << isEnabled();
    21. setEnabled(true);
    22. }
    23. QwtText FreqdBmPicker::trackerTextF( const QPointF &pos ) const {
    24. QString rtn;
    25. switch ( (int) std::log10(pos.x())) {
    26. case 9: rtn = QString("(%1GHz, %2dBm)").arg(pos.x()/1e9, 0, 'f', 2); break;
    27. case 8:
    28. case 7:
    29. case 6: rtn = QString("(%1MHz, %2dBm)").arg(pos.x()/1e6, 0, 'f', 2); break;
    30. case 5:
    31. case 4:
    32. case 3: rtn = QString("(%1kHz, %2dBm)").arg(pos.x()/1e3, 0, 'f', 2); break;
    33. case 2:
    34. case 1:
    35. case 0:
    36. default: rtn = QString("(%1Hz, %2dBm)").arg(pos.x(), 0, 'f', 2); break;
    37. }
    38. rtn = rtn.arg(pos.y(), 0, 'f', 1);
    39. return QwtText(rtn);
    40. }
    To copy to clipboard, switch view to plain text mode 

    Initialization and calling code. loadSweep() is called multiple times over the lifetime of the application
    Qt Code:
    1. SweepInspector::SweepInspector(QWidget *parent) : QWidget(parent), data(NULL), d_curve(NULL), picker(NULL) {
    2. setupUi(this);
    3. plot->setObjectName( "SweepData" );
    4. plot->setTitle( "RF Sweep" );
    5. plot->setAxisTitle( QwtPlot::xBottom, "Frequency");
    6. plot->setAxisTitle( QwtPlot::yLeft, QString( "Power Level (dBm)"));
    7. plot->setAutoReplot(true);
    8.  
    9. plot->enableAxis(QwtPlot::xBottom, true);
    10. plot->enableAxis(QwtPlot::yLeft, true);
    11. plot->enableAxis(QwtPlot::xTop, false);
    12. plot->enableAxis(QwtPlot::yRight, false);
    13.  
    14. canvas = new QwtPlotCanvas();
    15. canvas->setPalette( Qt::black );
    16. canvas->setBorderRadius(0);
    17. plot->setCanvas(canvas);
    18.  
    19. //Allow zooming / panning
    20. // zoomer = new QwtPlotZoomer( canvas );
    21. // zoomer->setRubberBandPen( QColor( Qt::white ) );
    22. // zoomer->setTrackerPen( QColor( Qt::white ) );
    23. panner = new QwtPlotPanner( canvas );
    24. panner->setMouseButton( Qt::MidButton );
    25.  
    26. picker = new FreqdBmPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, canvas);
    27.  
    28.  
    29. //Setup grid
    30. grid = new QwtPlotGrid();
    31. grid->enableXMin( true );
    32. grid->enableYMin( true );
    33. QColor color(Qt::gray); color.setAlpha(128);
    34. grid->setMajorPen( color, 1, Qt::DotLine );
    35. grid->setMinorPen( color, 1, Qt::DotLine );
    36. grid->attach( plot );
    37.  
    38. //format in kHz, MHz, GHz, not raw values
    39. plot->setAxisScaleDraw(QwtPlot::xBottom, new FreqScaleDraw);
    40.  
    41. //connects
    42. connect(timeIndex, SIGNAL(valueChanged(int)), this, SLOT(loadSweep(int)));
    43. connect(timeIndex, SIGNAL(sliderMoved(int)), this, SLOT(sliderMoved(int)));
    44. }
    45.  
    46. void SweepInspector::loadSweep(int index) {
    47. //load in new sweep values from data
    48. if (data == NULL) return;
    49.  
    50. //remove old data and get new
    51. if (d_curve) d_curve->attach(NULL);
    52. plot->detachItems();
    53. fsweep sweep = data->getSweep(index);
    54.  
    55. d_curve = new QwtPlotCurve( timestamp->text() ); //Qwt will delete() this when its done with it
    56. d_curve->setRenderHint( QwtPlotItem::RenderAntialiased );
    57. d_curve->setStyle( QwtPlotCurve::Lines );
    58. d_curve->setPen( QColor( Qt::yellow ), 2, Qt::SolidLine );
    59. d_curve->setSamples( sweep );
    60. d_curve->attach(plot);
    61.  
    62. delete(picker);
    63. picker = new FreqdBmPicker(QwtPlot::xBottom, QwtPlot::yLeft, QwtPlotPicker::CrossRubberBand, QwtPicker::AlwaysOn, canvas);
    64. connect(picker, SIGNAL(selected(QPointF)), this, SLOT(moved(QPointF)));
    65.  
    66. QwtInterval frange = data->limits(FREQ);
    67. plot->setAxisScale(QwtPlot::xBottom, frange.minValue(), frange.maxValue(), (frange.maxValue() - frange.minValue())/ 5.0);
    68. plot->setAxisScale(QwtPlot::yLeft, -135, 20, 10.0);
    69. plot->setTitle( QString("RF Sweep @ %1").arg(timestamp->text()) );
    70. //set maximum zoom out
    71. // zoomer->setZoomBase(QRectF(QPointF(frange.minValue(), 20), QPointF(frange.maxValue(), -135)));
    72. // zoomer->zoomBase();
    73. plot->replot();
    74. plot->repaint();
    75. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,326
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 880 Times in 828 Posts

    Default Re: QwtPlotPicker Subclass Segfaults

    A lot of code, but what is your question ?

    Uwe

  4. #4
    Join Date
    Dec 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotPicker Subclass Segfaults

    Haha, trees from the Forrest....


    Essentially, my QwtPlotPickers are not appearing on the plots, and the format functions are never called.

Similar Threads

  1. QStandardItem::appendRow() segfaults
    By i92guboj in forum Qt Programming
    Replies: 6
    Last Post: 22nd May 2014, 17:08
  2. Replies: 2
    Last Post: 15th April 2013, 06:33
  3. QSqlDatabase::open Segfaults
    By rich.remer in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2010, 16:32
  4. How to catch segfaults?
    By Daliphant in forum Newbie
    Replies: 4
    Last Post: 3rd July 2008, 14:17
  5. Anyone an idea why this code segfaults?
    By Kumosan in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2007, 05:53

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.