Details
Description
commit cd1d60ec71836d6c4e9cbfbf344ef9334a22cdc4 by Maurice Kalinowski changed qmqttconnection.cpp and added the following to qmqttclient.cpp:
// Once transport has connected, it will invoke // QMqttConnection::sendControlConnect to // handshake with the broker
however, when the mqtt client is used over a custom websocket based on QIODevice (just like in the by Qt provided mqtt websocket example), this doesn't work anymore, because the following code immediately returns true when the iodevice is already open. Because sendControlConnect() doesn't get called, the mqtt client never connects.
if (m_transportType == QMqttClient::IODevice) { if (m_transport->isOpen()) return true; if (!m_transport->open(QIODevice::ReadWrite)) { qWarning("Could not open Transport IO device"); m_internalState = BrokerDisconnected; return false; } return sendControlConnect(); }
Though it might not be the preferred way of solving the problem, the following works:
diff -u -r git-qt5-qtmqtt-orig/src/mqtt/qmqttconnection.cpp git-qt5-qtmqtt/src/mqtt/qmqttconnection.cpp --- git-qt5-qtmqtt-orig/src/mqtt/qmqttconnection.cpp 2018-03-08 16:16:43.974246846 +0100 +++ git-qt5-qtmqtt/src/mqtt/qmqttconnection.cpp 2018-03-08 16:17:39.353350689 +0100 @@ -125,7 +125,7 @@ if (m_transportType == QMqttClient::IODevice) { if (m_transport->isOpen()) - return true; + return sendControlConnect(); if (!m_transport->open(QIODevice::ReadWrite)) { qWarning("Could not open Transport IO device");
Attachments
For Gerrit Dashboard: QTBUG-66955 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
222708,3 | Fix connecting via an already open QIODevice transport | 5.11 | qt/qtmqtt | Status: MERGED | +2 | 0 |
231089,1 | Fix connecting via an already open QIODevice transport | wip/mqtt5 | qt/qtmqtt | Status: ABANDONED | 0 | 0 |