S
S
Sergey Doronovych2017-03-07 15:06:44
MySQL
Sergey Doronovych, 2017-03-07 15:06:44

How to connect Qt applications to mySql database?

You need to create a connection in the application to the database located on the site.
I'm trying to do this:

bool ControllerSQL::CreateConnection()
{
    Info = QSqlDatabase::addDatabase("QMYSQL");
    Info.setHostName("f63216y7.beget.tech");
    Info.setDatabaseName("f63216y7_water");
    Info.setUserName("f63216y7_water");
    Info.setPassword("12341234");

    if(Info.open())
        return true;
    qDebug()<<Info.lastError().text();
    return false;
}

But it writes an error:
"Host '91.202.129.179' is not allowed to connect to this MySQL server QMYSQL: Unable to connect"
Tell me what I'm doing wrong.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2017-03-07
@SergeyDoronovych

Can you connect to this database with any other sql client from your computer?
Looks like the database on the site just doesn't allow remote connections.

K
Konstantin Stepanov, 2017-03-07
@koronabora

And also - it is necessary to rebuild the mysql plugin.
According to the instructions in the manual:

cd %QTDIR%\qtbase\src\plugins\sqldrivers\mysql
  qmake "INCLUDEPATH+=C:/MySQL/include" "LIBS+=C:/MYSQL/MySQL Server <version>/lib/opt/libmysql.lib" mysql.pro
  nmake

Only in version 5.7 the source path will be: C:\Qt\5.7\Src\qtbase\src\plugins\sqldrivers\mysql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question