PDA

View Full Version : QT mysql connectivity issue on other than default port



mvbhavsar
30th May 2021, 16:21
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());
db.setHostName(jo.value("hostname").toString());
db.setDatabaseName(jo.value("dbname").toString());
db.setUserName(jo.value("username").toString());
db.setPassword(jo.value("password").toString());
db.setPort(jo.value("port").toInt());
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?

Cheers

Manish

ChristianEhrlicher
31st May 2021, 16:18
Wouldn't it be easier to answer the questions in the other forum before posting it here where due to the lack of the answers the same questions arise?