MyGit

emqx/qmqtt

Fork: 323 Star: 633 (更新于 1970-01-01 00:00:00)

license: NOASSERTION

Language: C++ .

MQTT client for Qt

最后发布版本: v1.0.3 ( 2023-05-17 02:13:02)

官方网址 GitHub网址

QMQTT

mqtt client for Qt 5 in maintenance status

Please compile the library with Qt >= 5.3 version. On Windows you need to specify CONFIG += NO_UNIT_TESTS, since gtest is not supported.

SSL is enabled by default, if the version of OpenSSL < 1.0.2, SSL may not be supported.

Disable the SSL in CMakeLists.txt (cmake):

option( ${PROJECT_NAME}_SSL "Enable SSL support for MQTT" OFF )

Disable the SSL with src/mqtt/qmqtt.pro (qmake):

CONFIG += QMQTT_NO_SSL

To add websocket support, compile the library with Qt >= 5.7, and specify 'CONFIG += QMQTT_WEBSOCKETS'. This also works when compiling qmqtt for WebAssembly.

Usage

In your QMake project, add:

QT += qmqtt

Connect using TCP:

#include "qmqtt.h"

QMQTT::Client *client = new QMQTT::Client(QHostAddress::LocalHost, 1883);
client->setClientId("clientId");
client->setUsername("user");
client->setPassword("password");
client->connectToHost();

Connect using SSL:

QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration();
// Add custom SSL options here (for example extra certificates)
QMQTT::Client *client = new QMQTT::Client("example.com", 8883, sslConfig);
client->setClientId("clientId");
client->setUsername("user");
client->setPassword("password");
// Optionally, set ssl errors you want to ignore. Be careful, because this may weaken security.
// See QSslSocket::ignoreSslErrors(const QList<QSslError> &) for more information.
client->ignoreSslErrors(<list of expected ssl errors>)
client->connectToHost();
// Here's another option to suppress SSL errors (again, be careful)
QObject::connect(client, &QMQTT::Client::sslErrors, [&](const QList<QSslError> &errors) {
    // Investigate the errors here, if you find no serious problems, call ignoreSslErrors()
    // to continue connecting.
    client->ignoreSslErrors();
});

Connect using WebSockets:

QMQTT::Client *client = new QMQTT::Client("ws://www.example.com/mqtt", "<origin>", QWebSocketProtocol::VersionLatest);
client->setClientId("clientId");
client->setUsername("user");
client->setPassword("password");
client->connectToHost();

Slots

void setHost(const QHostAddress& host);
void setPort(const quint16 port);
void setClientId(const QString& clientId);
void setUsername(const QString& username);
void setPassword(const QString& password);
void setKeepAlive(const int keepAlive);
void setCleanSession(const bool cleansess);
void setAutoReconnect(const bool value);
void setAutoReconnectInterval(const int autoReconnectInterval);
void setWillTopic(const QString& willTopic);
void setWillQos(const quint8 willQos);
void setWillRetain(const bool willRetain);
void setWillMessage(const QString& willMessage);

void connectToHost();
void disconnectFromHost();

quint16 subscribe(const QString& topic, const quint8 qos);
void unsubscribe(const QString& topic);

quint16 publish(const Message& message);

Signals

void connected();
void disconnected();
void error(const QMQTT::ClientError error);

void subscribed(const QString& topic, const quint8 qos);
void unsubscribed(const QString& topic);
void published(const quint16 msgid, const quint8 qos);
void pingresp();
void received(const QMQTT::Message& message);

Qt 6 support

This library has been developed and tested against Qt 5. Active work on it has stopped since Qt released its own mqtt module several years ago. There are currently no plans for further extensions except for smaller rectifications and bug fixing. At your own risk you may use it in Qt6 projects using cmake.

License

New BSD License

Contributors

@avsdev-cw, @alex-spataru, Benjamin Schmitz, @bf-bryants, @bog-dan-ro, @chsterz, @cncap, @ejvr, @ehntoo, Erik Botö, Guillaume Bour, @halfgaar, @hxcan, @jpnurmi, Kai Dohmen, @Kampfgnom, @keytee, @kollix, @KonstantinRitt, @maggu2810, @mwallnoefer, @NicoWallmeier, Niklas Wulf, Niraj Desai, @Psy-Kai, @rafaeldelucena, @rokm, @RoachLin, @sergey-kuzminov, sgaoemq, @Vortex375, ybq

Authors

@emqplus Feng Lee feng@emqx.io

@wguynes William Guynes wguynes@gmail.com

@wuming123057 Xuan huacai123057@163.com

最近版本更新:(数据更新于 1970-01-01 00:00:00)

2023-05-17 02:13:02 v1.0.3

2022-05-27 21:47:27 v1.0.2

2022-04-12 16:06:30 v1.0.1

2022-02-15 22:54:12 v1.0.0

2015-10-14 18:38:33 v0.1

主题(topics):

emqx, mqtt, mqtt-client, qmqtt, qt

emqx/qmqtt同语言 C++最近更新仓库

2024-11-05 23:57:44 PCSX2/pcsx2

2024-11-05 22:06:04 LizardByte/Sunshine

2024-11-05 00:42:13 ClickHouse/ClickHouse

2024-11-04 21:49:30 notepad-plus-plus/notepad-plus-plus

2024-11-03 22:31:09 MaaAssistantArknights/MaaAssistantArknights

2024-11-02 20:28:28 AaronFeng753/Waifu2x-Extension-GUI