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?