#ifndef HELPER_H #define HELPER_H #include #include #include class Helper : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON Q_PROPERTY(int state READ state NOTIFY stateChanged) Q_PROPERTY(int publishedValue READ publishedValue NOTIFY publishedValueChanged) Q_PROPERTY(int receivedValue READ receivedValue NOTIFY receivedValueChanged) public: Helper(QObject *parent = nullptr); ~Helper() override; int state() const { return m_state; } int publishedValue() const { return m_publishedValue; } int receivedValue() const { return m_receivedValue; } Q_INVOKABLE void openConnection(); Q_INVOKABLE void continueConnect(); public Q_SLOTS: void mqttConnected(); void mqttDisconnected(); void mqttErrorChanged(); void mqttStateChanged(); void mqttSubscriptionStateChanged(); void mqttSubscriptionMessageReceived(const QMqttMessage &message); void publishValue(); Q_SIGNALS: void stateChanged(); void publishedValueChanged(); void receivedValueChanged(); private: void createMqttSubscription(); int m_state = -1; int m_publishedValue = 0; int m_receivedValue = 0; QString m_clientId = QStringLiteral("qtmqttreconnectbug"); QString m_topicPath = QStringLiteral("qtmqtt/reconnect/bug"); QMqttClient *m_mqttClient = nullptr; QMqttSubscription *m_mqttSubscription = nullptr; QTimer *m_counterTimer = nullptr; }; #endif // HELPER_H