Solved Use an IPv6 as host with QSqlDatabase (Qt-4.8)
-
Hello everyone,
I try to connect to a mysql database with the IPv6 address of the server.
It seems that setHostname() method doesn't support an IPv6 argument...
How can I do that ?
Thank you
-
Hi and welcome to devnet,
Can you show your database connection code ?
-
Hello,
The connection to the database works with an IPv4 but I need to use an IPv6.
_lpdb->open() return false when I use an IPv6.
Here is my code:
QString _qstr_dbHostAddress = "fd02:0000:0000:0000:1030:00ff:fe00:0002"; *_lpdb = QSqlDatabase::addDatabase("QMYSQL"); _lpdb->setHostName(_qstr_dbHostAddress); _lpdb->setDatabaseName(_qstr_dbName); _lpdb->setUserName(_qstr_dbLogin); _lpdb->setPassword(_qstr_dbPassword); // Manage database connection if(_lpdb->open()) { // Refresh data of NDA Thread qDebug() << "NDAThread::run : connection to database success"; getDataFromDataBase(); // Close the database connection _lpdb->close(); } else { qDebug()<< "NDAThread::run : cannot connect to database"; //qDebug() << QSqlDatabase::drivers(); }
Thank you
-
I found the problem!
It is on mysql server not the client.
I have enabled the connection for the clients with IPv4 and IPv6 with a modification in /etc/mysql/my.cnf
// the parameter :: enables connection from all client with an IPv4 or an IPv6 bind-address = ::
There is more informations here : https://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_bind-address
Thank you