QT mysql connectivity issue on other than default port

  • Hi,

    I have QT mysql connectivity issue.

    I have created one docker instance where I have installed mysql. This mysql instance is running
    on port 6603 and not a regular port of 3306.
    This port is open and is accessible from outside as well. Now I am connecting to this mysql instance
    from all other applications which is not built using QT, like I am able to connect using node js or
    any other 3rd party mysql editor. This means there is no connectivity issue.
    But when I try to connect to this server using QSqlDatabase, it is either not connecting or says access denied.
    However, if I change the above server port from 6603 to default 3306, QT application is able to connect.
    Not getting where the things are going wrong. I have used below code of QT.

    QJsonObject jo = getConnectionDetails(); // getConnectionDetails has all values of actual connections.
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL",jo.value("conn_name").toString());
    if (!db.open()){
            error = db.lastError().databaseText();
            qDebug() << "Connection error: " + error;
            return false;
        return true;

    Above code is part of connector function.
    Please suggest why this happening?



  • Lifetime Qt Champion

    @Manish-Bhavsar said in QT mysql connectivity issue on other than default port:


    Did you actually check if it returns what you're expecting?

  • Lifetime Qt Champion


    Beside the port number.

    What exact error are you getting ?

    Do you have the MySQL plugins for your Qt installation ?
    How did you install Qt ?
    Which version is it ?
    On which OS ?

Log in to reply