QMYSQL driver not loaded, but source file not found to rebuild
-
Hi and welcome to devnet,
What exactly don't work ?
What error are you getting ?
Did you follow the step by step guide I wrote earlier ?
If so, did one of the point fail at any time ?
What version of Qt are you using ?
On what OS ?
With what compiler ? -
ldd /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/libqsqlmysql.so
linux-vdso.so.1 => (0x00007ffedfdda000)
libmysqlclient_r.so.16 => /usr/lib/x86_64-linux-gnu/libmysqlclient_r.so.16 (0x00007f949e3a8000)
libQt5Sql.so.5 => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/libQt5Sql.so.5 (0x00007f949e169000)
libQt5Core.so.5 => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/libQt5Core.so.5 (0x00007f949dade000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f949d75c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f949d393000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f949d175000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f949ce6c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f949cc52000)
libicui18n.so.51 => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/libicui18n.so.51 (0x00007f949c838000)
libicuuc.so.51 => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/libicuuc.so.51 (0x00007f949c4b2000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f949c2ae000)
libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f949c0ab000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f949bea3000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f949bb92000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f949b97b000)
/lib64/ld-linux-x86-64.so.2 (0x000055c820f7a000)
libicudata.so.51 => /home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers/../../lib/libicudata.so.51 (0x00007f949a232000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f9499fc1000) -
Did you also print the exact error you got ?
The plugin looks fine.
-
#include <QCoreApplication>
#include <QtSql/QSql>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlDriver>
#include <QtSql/QSqlQuery>
#include <QDebug>bool createConnection();
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if (!createConnection()){
qDebug() << "Not connected!";
return 1;
}
else{
qDebug() << "Connected";
QSqlQuery query;
query.exec("SELECT name FROM student");while (query.next()) { QString name = query.value(0).toString(); qDebug() << "name:" << name; } return 0; } return a.exec();
}
bool createConnection() {
// QApplication::addLibraryPath("/home/walter-j/Qt5.1.1/5.1.1/gcc_64/plugins/sqldrivers");
QSqlDatabase db = QSqlDatabase::addDatabase("QSLITE");
db.setHostName("localhost");
db.setDatabaseName("test.db");
db.setUserName("root");
db.setPassword("");
// db.setPort(3306);
// QSqlDriver *driver = QSqlDatabase::database().driver();
if(!db.open()){
qDebug() << "Database error occurred";
return false;
}return true;
}
#-------------------------------------------------
Project created by QtCreator 2016-12-15T19:04:16
#-------------------------------------------------
QT += core sql
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp
-
You are not use the MySQL driver and you are using the wrong name for the SQLite driver. It's
QSQLITE
. -
Print the text returned by
db.lastError()
Just saying that it doesn't work with the "Driver not loaded" message doesn't help much.
Based on your current code, it's not really surprising:
- You gave the driver name wrong.
- You are mixing the setup for the sqlite driver with the setup for a server based database.
One other important detail: do you have any of the SQL server running on your machine to connect to ? Is it properly configured ?