Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error expected constructor, destructor, or type conversion before ‘ when trying to register a structure from my C library

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

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Babs
    wrote on last edited by Babs
    #1

    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);
                                              ^
    1 Reply Last reply
    0
    • nageshN Offline
      nageshN Offline
      nagesh
      wrote on last edited by nagesh
      #2

      @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()

      B 3 Replies Last reply
      3
      • nageshN nagesh

        @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()

        B Offline
        B Offline
        Babs
        wrote on last edited by
        #3

        @nagesh it is a struct type

        1 Reply Last reply
        0
        • nageshN nagesh

          @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()

          B Offline
          B Offline
          Babs
          wrote on last edited by
          #4

          @nagesh i did the declaration with Q_DECLARE_METATYPE

          1 Reply Last reply
          0
          • nageshN nagesh

            @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()

            B Offline
            B Offline
            Babs
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved