O
O
Oleg Seledets2018-04-14 20:14:23
MySQL
Oleg Seledets, 2018-04-14 20:14:23

How to connect to MySQL from Qt Creator?

Hello, how to set up a connection to the database in mySQL from Qt Creator. What libraries to include, and how to install them?
Qt Creator 4.6.0 open source
Qt 5.10.1
MySQL 5.7
------------------------------------- ----
something seems to have changed. in the .pro file added an entry "QT += sql"
on the button hung up the event:

QSqlDatabase newDB;
    newDB = QSqlDatabase :: addDatabase("QMYSQL");

How can I now check the connection to my database?
------------------------------------
placed in the pro file
LIBS += "C:\mysql-5.7\bin"
        "C:\mysql-5.7\lib"

Now the button is:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("127.0.0.1");
    db.setDatabaseName("test1");
    db.setUserName("root");
    db.setPassword(" 123123123");

    if (!db.open())
    QMessageBox::critical(NULL,QObject::tr("Ошибка"),db.lastError().text());

At startup, it gave an error:
Driver not loaded Driver not loaded
After a couple of launches, it gave out
cannot find C:\mysql-5.7\bin: Permission denied

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Seledets, 2018-04-15
@oleja1ee7

Everything was decided after the actions that are described in the question itself.
And also, after all this, I used the advice on the site: https://gromr1.blogspot.ru/2014/04/compiling-drive...
Errors are no longer issued. Maybe someone helped.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question