I am facing an issue with Mysql Qt :
I have set up my Mysql database server with sample database schema and a table to test out.
code:
#include <QCoreApplication>
#include <iostream>
#include <string>
#include <QtSql>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("127.0.0.1");
db.setDatabaseName("testQtDB");
db.setUserName("root");
db.setPassword("password");
if(!db.open())
{
std::cout<<"data base not opened"<<std::endl;
}
else{
QSqlQuery query("SELECT * From emp");
std::cout<<"data table row size "<<query.size()<<std::endl;
for(int i=0;i<query.size();i++)
{
std::string data = QString(query.value(i).toString()).toStdString();
std::cout<<"data table row values "<<data<<std::endl;
}
}
return a.exec();
}
when I build there is know error but when run the application it says
QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
to over come this issue I have installed libqt5sql5-mysql and libmysqlclient_r but still it remains same
I am current running this program on:
Ubuntu 14.04
Qt 5.7
do I need to set the path of the mysql lib dir like we do in java for mysql connector.
Kindly help me with this, Thanks in advance.