Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

error expected constructor, destructor, or type conversion before ‘ when trying to register a structure from my C library



  • Hello, i'm trying to register a structure in my C library, in order to use it with signals and slots.

    #ifndef MQTTMANAGER_H
    #define MQTTMANAGER_H
    
    #include <QObject>
    #include <QMetaType>
    
    #include "core/interface/MQTTClient.h"
    
    
    
    class MqttManager: public QObject
    {
        Q_OBJECT
    
    public:
        MqttManager(QObject *parent = 0);
        void setupParameters();
        titanium_DbErrorCode doMqttClientCreate();
        titanium_DbErrorCode doConnect();
        titanium_DbErrorCode doPublish(QString& p_topic,const QString& p_payload, int p_qos=0,int p_retain=false);
        titanium_DbErrorCode doSubscribe(QString p_topic,int p_qos=0);
        void doUnsubscribe(QString& p_topic);
        void doDisconnect();
        void doMqttClientDestroy();
        static void message_Cb(void* p_ReceiverStruct, void* p_Data);
        void signalEmit(QString);
        static  MqttManager* m_manager;
    
    
    
    public slots:
    
    
    signals:
        void messageReceived(QString);
    
    private:
    
        QString m_hostname;
        int m_port;
        titanium_MQTTClient *m_client;
        titanium_MQTTConnectionSettings m_connectionSettingsMQTT;
        titanium_MQTTOnMessageCallback m_messageCallBack;
        bool m_autoReconnect;
    
    
    };
    
    
    Q_DECALARE_METATYPE(titanium_MQTTMessage);
    

    In my main function i use QRegisterMetatype because i have communication between threads:
    ```

    qRegisterMetaType<titanium_MQTTMessage>();
    
    I get the error:
     expected constructor, destructor, or type conversion before ‘;’ token
     Q_DECALARE_METATYPE(titanium_MQTTMessage);
                                              ^


  • @Babs what is this titanium_MQTTMessage?
    Is it structure type or instance of structure?

    https://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType-1

    It must be declared with Q_DECLARE_METATYPE()



  • @nagesh it is a struct type



  • @nagesh i did the declaration with Q_DECLARE_METATYPE



  • @nagesh thank you it solved i did the QRegisterMetaType just before connecting the signal to slot


Log in to reply