简体   繁体   English

包装QObject :: connect错误

[英]Wrapping QObject::connect error

I'm writing a subscription manager, the idea is that a signal and slot connection is created and multiple subscriptions can be hooked on the slot, when an update is received all subscriptions to the slot will be notified of the new data. 我正在写一个订阅管理器,其想法是创建一个信号和插槽连接,并且可以在插槽上挂接多个订阅,当收到更新时,将向该插槽的所有订阅通知新数据。

The issue is, that in my class that manages the subscriptions I am have a method called 'setupSubscription', here is the prototype: 问题是,在管理订阅的类中,我有一个名为“ setupSubscription”的方法,以下是原型:

    void setupSubscription(enum eSlotID ID
                          ,const QObject* pobjSender
                          ,const QMetaMethod& pobjSignal
                          ,const QMetaMethod& pobjSlot);

The enumerated type eSlotID contains a unique ID for each slot, the idea is that subscribers simple specify the ID to set-up a subscription. 枚举类型eSlotID包含每个插槽的唯一ID,其思想是订户可以简单地指定ID以建立订阅。

Its in the early stages of development and the code for setupSubscription: 它在开发的早期阶段以及setupSubscription的代码:

    void clsSlotSub::setupSubscription(enum eSlotID ID
                                      ,const QObject* pobjSender
                                      ,const QMetaMethod& pobjSignal
                                      ,const QMetaMethod& pobjSlot) {
        QObject::connect(pobjSender, pobjSignal, this, pobjSlot);
    }

Of course there is a lot more to go in this yet, but this causes an error on compile: 当然,这还有很多事情要做,但这会导致编译错误:

    error: no matching function for call to 'clsSlotSub::setupSubscription(clsSlotSub::eSlotID, Fcs::Mount*, void (Fcs::Mount::*)(Fcs::qfloat32), void (clsSlotSub::*)(float))'
                                ,&clsSlotSub::update2Elevation);
                                                              ^

I believe the prototype is correct having single stepped through the connect in the debugger before wrapping it in my setup method. 我相信,在将调试程序包装到我的设置方法中之前,只需在调试器中单步执行连接即可。

I'm not sure what the error means as the class implementation and prototype match and are present. 我不确定该错误意味着什么,因为类实现和原型匹配并存在。

Example of usage: 用法示例:

    msSlotSubMngr.setupSubscription(clsSlotSub::ELEVATION_ANGLE
                                   ,Fcs::Mount::GetRef()
                                  ,&Fcs::Mount::signalElevation
                                  ,&clsSlotSub::update2Elevation);

msSlotSubMngr is an instance of the slot subscription class. msSlotSubMngr是插槽预订类的实例。

This is the original code before wrapping and this compiles without any error: 这是包装之前的原始代码,并且编译时没有任何错误:

    QObject::connect(Fcs::Mount::GetRef()
                    ,&Fcs::Mount::signalElevation
                    ,mpobjElevStrip
                    ,&clsElevStrip::elevationChanged);

When I single set the working code, this is the prototype for the connect method: 当我单设置工作代码时,这是connect方法的原型:

     static QMetaObject::Connection connect(const QObject *sender
                                           ,const QMetaMethod &signal
                                           ,const QObject *receiver
                                           ,const QMetaMethod &method
                                           ,Qt::ConnectionType type = Qt::AutoConnection);

Declaration of eSlotID: eSlotID的声明:

    enum eSlotID {
    ...
    /*1003*/   ,ELEVATION_ANGLE
    ...
    };

Slot prototype: 插槽原型:

    void update2Elevation(float fltValue);

Slot implementation: 插槽实施:

    void clsSlotSub::update2Elevation(float fltValue) {
        qDebug() << "clsSlotSub::New elevation: " << fltValue;
    }

You need to show your calling code. 您需要显示您的呼叫代码。 From the error message, it looks like you just misspelled setupSubscription. 从错误消息中,您似乎只是拼错了setupSubscription。

Found the issue, which had absolutely nothing to do with the prototypes, however the error / cause wasn't reported by the compiler. 找到了与原型完全无关的问题,但是编译器未报告错误/原因。 It turned out that a required header was not included. 原来,没有包含必需的标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM