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

  • Lifetime Qt Champion

    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");
                // Manage database connection
                    // Refresh data of NDA Thread
                    qDebug() << "NDAThread::run : connection to database success";
                    // Close the database connection
                    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 :

    Thank you

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.