【问题标题】:Qwt for Qt: How to connect to signal with new signal/slot flavour?Qt for Qt:如何连接到具有新信号/插槽风格的信号?
【发布时间】:2014-06-03 08:49:52
【问题描述】:

我想连接到已选中的图例标签 SIGNAL。使用 Qts 旧 Signal/Slot-Syntax 一切都很完美,但我想使用新连接来启用编译时检查?关于如何通过新的 Signal/Slot-Syntax 连接它的任何想法?

这是我的代码:

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

使用旧语法一切都很好,使用新语法永远无法到达插槽。有任何想法吗?非常感谢!

【问题讨论】:

  • 你检查connect()函数调用的返回值了吗?
  • 是的。没有成功。错误信息:QObject::connect: signal not found in QwtLegend
  • 无论您的问题是什么 - 它应该与 Qwt 无关。该消息来自 qobject.cpp 中的 QObject::connectImpl ,使用调试器时,您应该能够找出在您的情况下为什么 senderMetaObject 是 nullptr。

标签: qt syntax signals qwt slot


【解决方案1】:

似乎5年后,情况仍然如此。旧的 SIGNAL/SLOT 语法适用于 Qwt 信号/插槽,但新语法不适用。你会得到“QObject::connect: signal not found in [Qwt ClassName]”。

作为参考,我目前使用的是 Qwt 6.1.2 和 Qt 5.9.6。

【讨论】:

    【解决方案2】:

    您的连接应该可以工作。

    我用您的示例代码对此进行了测试,它工作正常:

    定义:

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

    连接:

    ...
    connect(this, &TestClass::checked, this,  &TestClass::test);
    
    emit checked(QVariant(QString("test")), true, 1);
    ...
    

    插槽:

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

    希望能有所帮助。

    【讨论】:

    • 嗨!感谢您的帮助。当然,如果您连接到同一类的信号,它会起作用。但是尝试Qwt,你会得到错误信息QObject::connect: signal not found in QwtLegend。
    猜你喜欢
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 2015-03-14
    • 2016-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    相关资源
    最近更新 更多