Connecting to MySQL
-
wrote on 14 Sept 2014, 14:45 last edited by
Here is a simple example of connecting to the database:
@#include <QCoreApplication>
#include <QDebug>
#include <QtSql/QSqlDatabase>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "autoservise"); db.setHostName("localhost"); db.setDatabaseName("autoservise"); db.setUserName("root"); db.setPassword("pass"); return a.exec();
}@
The output is: qmysql driver not loaded. But the driver is active.
Did everything as written in the documentation.
Turned four files:
libqsqlmysql.a
libqsqlmysqld.a
libqsqlmysql.dll
libqsqlmysqld.dllThrows files in a folder: E:\qt\Qt5.3.1\5.3\mingw482_32\plugins\sqldrivers. And the result is the same. What could be the problem?
-
Hi and welcome to devnet,
Do you have the MySQL client library installed ?
-
wrote on 20 Sept 2014, 10:33 last edited by
Yes. I installed all the libraries that were offered during the server installation.
-
wrote on 20 Sept 2014, 13:19 last edited by
Hi
In my project i did this,@
db = QSqlDatabase::addDatabase("QODBC"); db.setHostName("localHost"); db.setPort(3306); db.setDatabaseName("DRIVER={MySQL ODBC 5.2w Driver};DATABASE={joint_insp};UID={root}"); db.setUserName("root"); db.setPassword("root"); if(!db.open()) showErrorDialog("Database Not Opened");
@
for this you need to install ODBC driver, or it my be already installed in your system(with mysql installation). You can check in "Control Panel\All Control Panel Items\Administrative Tools\Data Sources(ODBC)" and in drivers tab.
-
So next step is to let your program know where the MySQL client libraries are.
In the Run part of the Project panel, edit the PATH variable and the the path to the folder where the MySQL client libraries can be found
-
wrote on 20 Sept 2014, 15:56 last edited by
"So next step is to let your program know where the MySQL client libraries are.
In the Run part of the Project panel, edit the PATH variable and the the path to the folder where the MySQL client libraries can be found"It did not help. Writes:
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7 -
Did you check what error message is returned ?
4/7