! *\brief called when a message is received by a topic belonging to one of subscriptions of the client. * It passes the message to the appropriate MQTTSubscription which will pass it to the appropriate MQTTTopic */
| 1047 | * It passes the message to the appropriate MQTTSubscription which will pass it to the appropriate MQTTTopic |
| 1048 | */ |
| 1049 | void MQTTClient::MQTTSubscriptionMessageReceived(const QMqttMessage& msg) { |
| 1050 | // Decide to interpret retain message or not |
| 1051 | if (!msg.retain() || m_MQTTRetain) { |
| 1052 | // If this is the first message from the topic, save its name |
| 1053 | if (!m_topicNames.contains(msg.topic().name())) |
| 1054 | m_topicNames.push_back(msg.topic().name()); |
| 1055 | |
| 1056 | // Pass the message and the topic name to the MQTTSubscription which contains the topic |
| 1057 | for (auto* subscription : m_MQTTSubscriptions) { |
| 1058 | if (checkTopicContains(subscription->subscriptionName(), msg.topic().name())) { |
| 1059 | subscription->messageArrived(msg); |
| 1060 | Q_EMIT messagedReceived(); |
| 1061 | break; |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | // if the message was received by the will topic, update the last message received by it |
| 1066 | if (msg.topic().name() == m_MQTTWill.willTopic) { |
| 1067 | m_MQTTWill.willLastMessage = QLatin1String(msg.payload()); |
| 1068 | Q_EMIT MQTTTopicsChanged(); |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | /*! |
| 1074 | *\brief Handles some of the possible errors of the client, using MQTTErrorWidget |
nothing calls this directly
no test coverage detected