[SOLVED] Mysql driver not loaded error (Ubuntu Desktop 12.04)
-
this topic is copy of "this topic.":http://qt-project.org/forums/viewthread/35581/
I copied it because I wrote previous topic to wrong branch of forum and seems that is cause not get answer.OS: Ubuntu Desktop 12.04
QT: 5.1.1
Mysql Driver: compiled from source
ldd command show that everything ok
@test(at)penguin:~/Qt/5.1.1/gcc/plugins/sqldrivers$ ldd libqsqlmysql.so
linux-gate.so.1 => (0xb77da000)
libmysqlclient.so.18 => /usr/lib/i386-linux-gnu/libmysqlclient.so.18 (0xb7494000)
libQt5Sql.so.5 => /home/test/Qt/5.1.1/gcc/lib/libQt5Sql.so.5 (0xb7454000)
libQt5Core.so.5 => /home/test/Qt/5.1.1/gcc/lib/libQt5Core.so.5 (0xb6fd0000)
libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb6eeb000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb6d41000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb6d2b000)
libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0xb6d26000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xb6d0a000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb6cde000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb6cc0000)
libicui18n.so.51 => /home/test/Qt/5.1.1/gcc/lib/libicui18n.so.51 (0xb6a9e000)
libicuuc.so.51 => /home/test/Qt/5.1.1/gcc/lib/libicuuc.so.51 (0xb6925000)
libgthread-2.0.so.0 => /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 (0xb6921000)
librt.so.1 => /lib/i386-linux-gnu/librt.so.1 (0xb6918000)
libglib-2.0.so.0 => /lib/i386-linux-gnu/libglib-2.0.so.0 (0xb681f000)
/lib/ld-linux.so.2 (0xb77db000)
libicudata.so.51 => /home/test/Qt/5.1.1/gcc/lib/libicudata.so.51 (0xb52d6000)
libpcre.so.3 => /lib/i386-linux-gnu/libpcre.so.3 (0xb5299000)@
connection code
@db = new QSqlDatabase();
db->addDatabase("QMYSQL", "DB");
db->setHostName("localhost");
db->setDatabaseName("testdb");
db->setUserName("testuser");
db->setPassword("test12");qDebug() << "drivers: "<< QSqlDatabase::drivers(); if (db->open()) qDebug() << "Success!"; else qDebug() << db->lastError().text();@
Error:
@Starting /home/test/QtProjects/build-MySQLGUI-Desktop_Qt_5_1_0_GCC_32bit-Release/MySQLGUI...
drivers: ("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7")
"Driver not loaded Driver not loaded"@made copy of file
~/Qt/5.1.1/gcc/plugins/sqldrivers/libqsqlmysql.so
to project source folder and to build folder. Also created sqldrivers subfolder in project source and build folder and made copy of file
/usr/lib/i386-linux-gnu/libmysqlclient.so
to this sqldrivers folder.What do I do wrong? Why I got error “Driver not loaded Driver not loaded”?
Pz, any suggestion.
-
Qt gurus, please, help
-
Solution was found by user bpalmer7440.
@I notice your posts about the problems you were having getting the MYSQL
driver to load in Qt. I was having the exact same problem (even though I
had all of the libraries and they could be found). At any rate I finally
found a thread where it became evident that the addDatabase function was
static on the QSqlDatabase class and doing this worked:QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
instead of this:
QSqlDatabase db;
db.addDatabase("QMYSQL");This fixed my problem. I'm not sure why..
-Brian@
It is fixed my problem too. Thank you everyone, especially Brian.