Results 1 to 5 of 5

Thread: QwtPlotPicker Subclass Segfaults

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

    Exclamation QwtPlotPicker Subclass Segfaults

    I am trying to subclass QwtPlotPicker to change the default value for the displayed text, and everything I am doing causes segfaults. I have spent a couple hours at this with no avail. I am using latest Qwt from SVN (6.x series).


    My QwtPlotPicker subclass .h:
    Qt Code:
    1. class FreqdBmPicker : public QwtPlotPicker {
    2. public:
    3. FreqdBmPicker( QWidget *canvas );
    4. private:
    5. virtual QwtText trackerTextF( const QPointF &pos ) const;
    6. };
    To copy to clipboard, switch view to plain text mode 

    My QwtPlotPicker subclass .cpp:
    Qt Code:
    1. FreqdBmPicker::FreqdBmPicker( QWidget *canvas ): QwtPlotPicker( canvas ) {
    2. setTrackerMode( QwtPicker::AlwaysOn );
    3. setRubberBand( QwtPlotPicker::CrossRubberBand );
    4. setStateMachine( new QwtPickerTrackerMachine() );
    5. setTrackerPen(QColor(Qt::cyan));
    6. setRubberBandPen(QColor(Qt::cyan));
    7. }
    8. QwtText FreqdBmPicker::trackerTextF( const QPointF &pos ) const {
    9. QString rtn;
    10. switch ( (int) std::log10(pos.x())) {
    11. case 9: rtn = QString("(%1GHz, %2dBm)").arg(pos.x()/1e9, 0, 'f', 2).arg(pos.y(), 0, 'f', 1); break;
    12. case 8:
    13. case 7:
    14. case 6: rtn = QString("(%1MHz, %2dBm)").arg(pos.x()/1e6, 0, 'f', 2).arg(pos.y(), 0, 'f', 1); break;
    15. case 5:
    16. case 4:
    17. case 3: rtn = QString("(%1kHz, %2dBm)").arg(pos.x()/1e3, 0, 'f', 2).arg(pos.y(), 0, 'f', 1); break;
    18. case 2:
    19. case 1:
    20. case 0: rtn = QString("(%1Hz, %2dBm)").arg(pos.x(), 0, 'f', 2).arg(pos.y(), 0, 'f', 1); break;
    21. }
    22. return QwtText(rtn);
    23. }
    To copy to clipboard, switch view to plain text mode 

    In the calling *.cpp class:
    Qt Code:
    1. canvas = new QwtPlotCanvas();
    2. canvas->setPalette( Qt::black );
    3. canvas->setBorderRadius(0);
    4. plot->setCanvas(canvas);
    5. TimeFreqPicker *pkr = new TimeFreqPicker(plot->canvas());
    To copy to clipboard, switch view to plain text mode 

    It appears to run, but the minute I click anywhere on the plot, it immediately segfaults. gdb backtrace:
    Qt Code:
    1. #0 0x00007ffff6ffe26c in QwtPicker::adjustedPoints(QPolygon const&) const () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    2. #1 0x00007ffff6fffb20 in QwtPicker::updateDisplay() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    3. #2 0x00007ffff6ffec76 in QwtPicker::eventFilter(QObject*, QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    4. #3 0x00007ffff754a9e5 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
    5. #4 0x00007ffff78e843c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
    6. #5 0x00007ffff78ed470 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
    7. #6 0x00007ffff754a7a5 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
    8. #7 0x00007ffff7920295 in QWidgetPrivate::setGeometry_sys(int, int, int, int, bool) () from /usr/lib64/libQt5Widgets.so.5
    9. #8 0x00007ffff7920f89 in QWidget::setGeometry(QRect const&) () from /usr/lib64/libQt5Widgets.so.5
    10. #9 0x00007ffff7031334 in QwtPlot::updateLayout() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    11. #10 0x00007ffff7034491 in QwtPlot::event(QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    12. #11 0x00007ffff78e845c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
    13. #12 0x00007ffff78ed470 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
    14. #13 0x00007ffff754a7a5 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
    15. #14 0x00007ffff754c63f in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQt5Core.so.5
    16. #15 0x00007ffff7031d02 in QwtPlot::replot() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    17. #16 0x00007ffff7065fd1 in QwtPlotZoomer::zoom(QRectF const&) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    18. #17 0x00007ffff7066581 in QwtPlotZoomer::end(bool) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    19. #18 0x00007ffff700128a in QwtPicker::transition(QEvent const*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    20. #19 0x00007ffff6ffec01 in QwtPicker::eventFilter(QObject*, QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
    21. #20 0x00007ffff754a9e5 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
    22. #21 0x00007ffff78e843c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
    23. #22 0x00007ffff78edda6 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
    24. ....
    To copy to clipboard, switch view to plain text mode 

    What am I doing wrong?

  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: QwtPlotPicker Subclass Segfaults

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

    Uwe

  3. #3
    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 

  4. #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: QwtPlotPicker Subclass Segfaults

    A lot of code, but what is your question ?

    Uwe

  5. #5
    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, 18:08
  2. Replies: 2
    Last Post: 15th April 2013, 07:33
  3. QSqlDatabase::open Segfaults
    By rich.remer in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2010, 17:32
  4. How to catch segfaults?
    By Daliphant in forum Newbie
    Replies: 4
    Last Post: 3rd July 2008, 15:17
  5. Anyone an idea why this code segfaults?
    By Kumosan in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2007, 06: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.