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:
public:
private:
};
class FreqdBmPicker : public QwtPlotPicker {
public:
FreqdBmPicker( QWidget *canvas );
private:
virtual QwtText trackerTextF( const QPointF &pos ) const;
};
To copy to clipboard, switch view to plain text mode
My QwtPlotPicker subclass .cpp:
setStateMachine( new QwtPickerTrackerMachine() );
setTrackerPen
(QColor(Qt
::cyan));
setRubberBandPen
(QColor(Qt
::cyan));
}
switch ( (int) std::log10(pos.x())) {
case 9: rtn
= QString("(%1GHz, %2dBm)").
arg(pos.
x()/1e9,
0,
'f',
2).
arg(pos.
y(),
0,
'f',
1);
break;
case 8:
case 7:
case 6: rtn
= QString("(%1MHz, %2dBm)").
arg(pos.
x()/1e6,
0,
'f',
2).
arg(pos.
y(),
0,
'f',
1);
break;
case 5:
case 4:
case 3: rtn
= QString("(%1kHz, %2dBm)").
arg(pos.
x()/1e3,
0,
'f',
2).
arg(pos.
y(),
0,
'f',
1);
break;
case 2:
case 1:
case 0: rtn
= QString("(%1Hz, %2dBm)").
arg(pos.
x(),
0,
'f',
2).
arg(pos.
y(),
0,
'f',
1);
break;
}
}
FreqdBmPicker::FreqdBmPicker( QWidget *canvas ): QwtPlotPicker( canvas ) {
setTrackerMode( QwtPicker::AlwaysOn );
setRubberBand( QwtPlotPicker::CrossRubberBand );
setStateMachine( new QwtPickerTrackerMachine() );
setTrackerPen(QColor(Qt::cyan));
setRubberBandPen(QColor(Qt::cyan));
}
QwtText FreqdBmPicker::trackerTextF( const QPointF &pos ) const {
QString rtn;
switch ( (int) std::log10(pos.x())) {
case 9: rtn = QString("(%1GHz, %2dBm)").arg(pos.x()/1e9, 0, 'f', 2).arg(pos.y(), 0, 'f', 1); break;
case 8:
case 7:
case 6: rtn = QString("(%1MHz, %2dBm)").arg(pos.x()/1e6, 0, 'f', 2).arg(pos.y(), 0, 'f', 1); break;
case 5:
case 4:
case 3: rtn = QString("(%1kHz, %2dBm)").arg(pos.x()/1e3, 0, 'f', 2).arg(pos.y(), 0, 'f', 1); break;
case 2:
case 1:
case 0: rtn = QString("(%1Hz, %2dBm)").arg(pos.x(), 0, 'f', 2).arg(pos.y(), 0, 'f', 1); break;
}
return QwtText(rtn);
}
To copy to clipboard, switch view to plain text mode
In the calling *.cpp class:
canvas->setPalette( Qt::black );
canvas->setBorderRadius(0);
plot->setCanvas(canvas);
TimeFreqPicker *pkr = new TimeFreqPicker(plot->canvas());
canvas = new QwtPlotCanvas();
canvas->setPalette( Qt::black );
canvas->setBorderRadius(0);
plot->setCanvas(canvas);
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:
#0 0x00007ffff6ffe26c in QwtPicker::adjustedPoints(QPolygon const&) const () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#1 0x00007ffff6fffb20 in QwtPicker::updateDisplay() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#2 0x00007ffff6ffec76 in QwtPicker::eventFilter(QObject*, QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#3 0x00007ffff754a9e5 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#4 0x00007ffff78e843c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#5 0x00007ffff78ed470 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#6 0x00007ffff754a7a5 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#7 0x00007ffff7920295 in QWidgetPrivate::setGeometry_sys(int, int, int, int, bool) () from /usr/lib64/libQt5Widgets.so.5
#8 0x00007ffff7920f89 in QWidget::setGeometry(QRect const&) () from /usr/lib64/libQt5Widgets.so.5
#9 0x00007ffff7031334 in QwtPlot::updateLayout() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#10 0x00007ffff7034491 in QwtPlot::event(QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#11 0x00007ffff78e845c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#12 0x00007ffff78ed470 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#13 0x00007ffff754a7a5 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#14 0x00007ffff754c63f in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQt5Core.so.5
#15 0x00007ffff7031d02 in QwtPlot::replot() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#16 0x00007ffff7065fd1 in QwtPlotZoomer::zoom(QRectF const&) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#17 0x00007ffff7066581 in QwtPlotZoomer::end(bool) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#18 0x00007ffff700128a in QwtPicker::transition(QEvent const*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#19 0x00007ffff6ffec01 in QwtPicker::eventFilter(QObject*, QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#20 0x00007ffff754a9e5 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#21 0x00007ffff78e843c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#22 0x00007ffff78edda6 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
....
#0 0x00007ffff6ffe26c in QwtPicker::adjustedPoints(QPolygon const&) const () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#1 0x00007ffff6fffb20 in QwtPicker::updateDisplay() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#2 0x00007ffff6ffec76 in QwtPicker::eventFilter(QObject*, QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#3 0x00007ffff754a9e5 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#4 0x00007ffff78e843c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#5 0x00007ffff78ed470 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#6 0x00007ffff754a7a5 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#7 0x00007ffff7920295 in QWidgetPrivate::setGeometry_sys(int, int, int, int, bool) () from /usr/lib64/libQt5Widgets.so.5
#8 0x00007ffff7920f89 in QWidget::setGeometry(QRect const&) () from /usr/lib64/libQt5Widgets.so.5
#9 0x00007ffff7031334 in QwtPlot::updateLayout() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#10 0x00007ffff7034491 in QwtPlot::event(QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#11 0x00007ffff78e845c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#12 0x00007ffff78ed470 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#13 0x00007ffff754a7a5 in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#14 0x00007ffff754c63f in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) () from /usr/lib64/libQt5Core.so.5
#15 0x00007ffff7031d02 in QwtPlot::replot() () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#16 0x00007ffff7065fd1 in QwtPlotZoomer::zoom(QRectF const&) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#17 0x00007ffff7066581 in QwtPlotZoomer::end(bool) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#18 0x00007ffff700128a in QwtPicker::transition(QEvent const*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#19 0x00007ffff6ffec01 in QwtPicker::eventFilter(QObject*, QEvent*) () from /home/nickp/code/SpectralSignalHound-Viewer/qwt/lib/libqwt.so.6
#20 0x00007ffff754a9e5 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) () from /usr/lib64/libQt5Core.so.5
#21 0x00007ffff78e843c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
#22 0x00007ffff78edda6 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/libQt5Widgets.so.5
....
To copy to clipboard, switch view to plain text mode
What am I doing wrong?
Bookmarks