QT MQTT TLS Failed
-
Development environment
1.windows10 x64
2.qt and mqtt version 5.15.2
3.compiler: mingw 8.1
Question:
I tried to add the TLS function on the basis of mqtt client to facilitate secure transmission, but after turning on TLS, I cannot connect to the server. The error message is 256 QMqttClient::TransportInvalidCode:
m_client = new QMqttClient(this);
const QString hostname{"test.mosquitto.org"};
const quint16 port = 8883;
if(QSslSocket::supportsSsl())
{
qDebug()<<"SSL SUPORTED";
};
QSslCertificate cert = QSslCertificate(pem,QSsl::Pem);
QSslConfiguration conf;
conf.setCaCertificates({cert});
conf.setProtocol(QSsl::TlsV1_2);
m_client->setHostname(hostname);
m_client->setPort(port);
QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
m_client->connectToHostEncrypted(conf);