1

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.

Saikrishna
  • 87
  • 2
  • 11
  • does we need to set any build Environment for the project properties....!! – Saikrishna Jan 30 '17 at 11:01
  • 3
    Duplicate of https://stackoverflow.com/questions/40328372/qmysql-driver-not-loaded-but-its-available and https://stackoverflow.com/questions/37369480/qsqldatabase-qmysql-driver-not-loaded-on-ubuntu-15-04-64bits – peppe Jan 30 '17 at 11:19
  • Thanks for the answer i solved the problem @peppe – Saikrishna Jan 31 '17 at 08:12

0 Answers0