Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. issues establishing connection between broker and Qt using Qmqtt
Qt 6.11 is out! See what's new in the release blog

issues establishing connection between broker and Qt using Qmqtt

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 389 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yina
    wrote on last edited by
    #1

    Hello

    I am trying to establish a MQTT connection between my app and an external broker with a certificate. . When I try to connect to the host I do get a log on the broker but on QT I get the "QMqttClient::TransportInvalid" error. Anyone know what the issue could be?

    Logging Ubuntu mosquitto broker behind nginx proxy:
    1675345598: New connection from 172.17.0.1:60662 on port 8883.
    1675345598: Client <unknown> closed its connection.

    It does work with other applications like MqttBox.

    Here is the code I use:

        QFile certFile(":/ca.cer");
        certFile.open(QIODevice::ReadOnly);
        client = new QMqttClient(this);
        QSslCertificate cert = QSslCertificate(&certFile, QSsl::Der);
        QSslConfiguration conf;
        conf.setProtocol(QSsl::TlsV1_2);
        conf.setCaCertificates({cert});
        QSslConfiguration::setDefaultConfiguration(conf);
    
    
        QObject::connect(client, &QMqttClient::stateChanged, [](QMqttClient::ClientState state){
            if(state == QMqttClient::Disconnected)
                qDebug() << " State: Disconnected";
            else if(state == QMqttClient::Connecting)
                qDebug() << " State: Connecting";
            else if(state == QMqttClient::Connected)
                qDebug() << " State: Connected";
        });
    
        QObject::connect(client, &QMqttClient::errorChanged, [](QMqttClient::ClientError error){
             qDebug() << "error Mqtt: " << error;
    
         });
    
        client->setHostname(hostName);
        client->setPort(portName);
        client->setUsername(userName);
        client->setPassword(passWord);
        client->setClientId(clientId);
        client->setProtocolVersion(QMqttClient::MQTT_3_1_1);
    
        client->connectToHostEncrypted(conf);```
    

    Kind regards
    Yina

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved