QwtLegend signal 'clicked' not found
Brought to you by:
rathmann
This is the error message:
qt.core.qobject.connect: QObject::connect(QwtLegend, QwtLegend): signal not found
I am using:
qwt 6.3.0
Qt 6.10.1_MinGW_64
Qt Creator 18.0.0
I ran into this problem in the middle of a large project.
I was unable to figure it out so I made a minimal example that reproduces the problem.
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
QwtPlot* plot = new QwtPlot;
this->setCentralWidget(plot);
plot->setTitle( "Plot Demo" );
plot->setCanvasBackground( Qt::white );
plot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0);
QwtLegend* legend = new QwtLegend();
legend->setDefaultItemMode(QwtLegendData::Mode::Clickable);
//legend->setDefaultItemMode(QwtLegendData::Mode::Checkable);
connect(legend, &QwtLegend::clicked, [this] () { qDebug() << "test"; } );
//connect(legend, &QwtLegend::checked, [this] () { qDebug() << "test"; } );
//connect(legend, SIGNAL(clicked(const QVariant &itemInfo, int index)), this, SLOT(legendClicked(const QVariant &itemInfo, int index)));
//connect(legend, SIGNAL(checked(const QVariant &itemInfo, bool on, int index)), this, SLOT(legendClicked(const QVariant &itemInfo, bool on, int index)));
plot->insertLegend(legend);
QwtPlotGrid *grid = new QwtPlotGrid();
grid->attach( plot );
QwtPlotCurve *curve = new QwtPlotCurve();
curve->setTitle( "Pixel Count" );
curve->setPen( Qt::blue, 4 ),
curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );
QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse, QBrush( Qt::yellow ), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
curve->setSymbol( symbol );
QPolygonF points;
points << QPointF( 0.0, 4.4 ) << QPointF( 1.0, 3.0 )
<< QPointF( 2.0, 4.5 ) << QPointF( 3.0, 6.8 )
<< QPointF( 4.0, 7.9 ) << QPointF( 5.0, 7.1 );
curve->setSamples( points );
curve->attach( plot );
plot->resize( 600, 400 );
plot->show();
}
void MainWindow::legendClicked(const QVariant &itemInfo, int index){}
void MainWindow::legendChecked(const QVariant &itemInfo, bool on, int index){}
It does not matter if I try to connect string-based or functor-based
I get the run-time error:
qt.core.qobject.connect: QObject::connect(QwtLegend, QwtLegend): signal not found
I looked in the source code 'qwt_legend.h'
Q_SIGNALS:
/*!
A signal which is emitted when the user has clicked on
a legend label, which is in QwtLegendData::Clickable mode.
\param itemInfo Info for the item item of the
selected legend item
\param index Index of the legend label in the list of widgets
that are associated with the plot item
\note clicks are disabled as default
\sa setDefaultItemMode(), defaultItemMode(), QwtPlot::itemToInfo()
*/
void clicked( const QVariant& itemInfo, int index );
What is going on? Is this a bug or am I doing something wrong?
Anonymous
I think I am the problem. I found what I was doing wrong.