Qwt for Qt: How to connect to signal with new signal/slot flavour?

爷,独闯天下 提交于 2019-12-25 16:55:55

问题


I want to to connect to legend-label SIGNAL checked. With Qts old Signal/Slot-Syntax all is perfect, but i want to use the new connection to enable compile-time check? Any idea on how to connect it via new Signal/Slot-Syntax?

This is my code:

connect( m_plotLegend, SIGNAL( checked( const QVariant &, bool, int ) ), SLOT(legendChecked( const QVariant &, bool ) ) );
//connect(m_plotLegend, &QwtLegend::checked, this, &MeasurePlot::legendChecked);

With oldy syntax all is fine, with the new syntax the slot is never reached. Any ideas? Thank you very much!


回答1:


Your connect should work.

I test this with your Examplecode and it works fine:

Definition:

...
private slots:
void test(const QVariant &, bool);

signals:
void checked( const QVariant &, bool, int );
...

Connection:

...
connect(this, &TestClass::checked, this,  &TestClass::test);

emit checked(QVariant(QString("test")), true, 1);
...

Slot:

void TestClass::test(const QVariant &, bool)
{
...
}

Hope that helps a little bit.




回答2:


It seems 5 years later, this is still the case. Old SIGNAL/SLOT syntax works for Qwt signal/slots but the new syntax does not. You will get "QObject::connect: signal not found in [Qwt ClassName]."

For reference, I'm currently using Qwt 6.1.2 and Qt 5.9.6.



来源:https://stackoverflow.com/questions/24010844/qwt-for-qt-how-to-connect-to-signal-with-new-signal-slot-flavour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!