Client(const QHostAddress& host = QHostAddress::LocalHost,
const quint16 port = 1883,
QObject* parent = NULL);
#ifndef QT_NO_SSL
Client(const QString& hostName,
const quint16 port,
const QSslConfiguration& config,
const bool ignoreSelfSigned=false,
QObject* parent = NULL);
#endif // QT_NO_SSL
这个是官网自带的MQTT,可以好清楚看到,当使用SSL认证的时候,是用QString& hostName,如果不用SSL认证就是用const QHostAddress& host;
这里有一个参考使用方法http://www.mamicode.com/info-detail-2597790.html,大概是这样子的,
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");
client->connectToHost();
可以看到,这是用了.com的域名的,现在有一个MQTT的服务器,同事给了我ip和port,有帐户名和密码,还有ca证书,pem格式的,我把实例中的example.com用ip代替,发现是连接不上的,现在我的问题是,我有ip地址,port,帐户密码,ca证书,怎么才能通过ssl认证连接上MQTT服务器