Skip to content Skip to sidebar Skip to footer

Qt C++ Library In Android Eclipse Project: Qsqlite Driver Not Loaded

I've created a Qt dynamic lib that uses Qt SQL to open an SQLite database, but I'm getting this error: QSqlDatabase: QSQLITE driver not loaded QSqlDatabase: available drivers: Th

Solution 1:

Eventually I stepped into the Qt sources to see how the SQLITE plugin is loaded (for the desktop build at least).

The relevant function was QFactoryLoader::update(). In it I noticed that it iterates all the directories in QCoreApplication::libraryPaths():

QStringListpaths= QCoreApplication::libraryPaths();
for (inti=0; i < paths.count(); ++i) {

If any of them has a sub-directory named "sqldrivers", it goes inside it and tries to load all the dynamic libraries in that sub-directory.

I then printed out the library paths in a test project I ran directly from Qt Creator - qDebug() << a.libraryPaths();, and I saw this path - /data/data/org.qtproject.example.untitled/qt-reserved-files/plugins. In this directory on my android phone there was a subdirectory named sqldrivers, that contained a single file - libqsqlite.so.

I then checked the .java files, and indeed QtActivity::startApp() adds the library path:

booleanbundlingQtLibs=false;
if (m_activityInfo.metaData.containsKey("android.app.bundle_local_qt_libs")
    && m_activityInfo.metaData.getInt("android.app.bundle_local_qt_libs") == 1) {
    localPrefix = getApplicationInfo().dataDir + "/";
    pluginsPrefix = localPrefix + "qt-reserved-files/";
    cleanOldCacheIfNecessary(localPrefix, pluginsPrefix);
    extractBundledPluginsAndImports(pluginsPrefix);
    bundlingQtLibs = true;
}

The solution then would be to ensure that there is a sqldrivers/libqsqlite.so somewhere on the phone, and then add the parent folder of sqldrivers to the library path using QCoreApplication::addLibraryPath().

Post a Comment for "Qt C++ Library In Android Eclipse Project: Qsqlite Driver Not Loaded"