Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

PySide + Sqlite = Driver not loaded



  • Despite a great deal of Googling, I can't find why Qt is unable to find the Sqlite plugin for a QSqlDatabase.
    Things I have verified:
    libqt-sql-sqlite package installed
    /usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libsqlite.so is present
    "/usr/lib/x86_64-linux-gnu/qt4/plugins/" is present in the QApplication libraryPaths()
    Tried instantiating QApplication prior to call to addDatabase so that library search paths are initialised.

    When I call drivers() on the QSqlDatabase, it listed QSQLITE as an available driver. But when I call addDatabase("QSQLITE"), the database is not open/valid with a lastError of "Driver not loaded Driver not loaded". I've got Qt/PySide installed from Ubuntu packages, so I can't (as far as I know) do the configure option to force Sql driver building/static-linking.
    Any pointers are greatly appreciated.

    OS: Ubuntu 11.10 x64
    Current latest packages of Qt/PySide.

    I can't help thinking this must be a bug, by the fact QSqlDatabase tells me the driver is available, with the drivers() list as well as even explicitly stating "isDriverAvailable("QSQLITE")" -> True, but then failing to add a database with this driver as the driver/plugin isn't loaded.



  • Ok, found the problem. User error as usual. I failed to notice that the addDatabase function was a static and not a bound method. I was deriving from QSqlDatabase and calling it on self, my bad. Though I'm a little perplexed as to why the lastError function returned "Driver not loaded"..that threw me off a bit. Calling the static addDatabase shouldn't have changed the state of my derived object, so I don't know where that "driver not loaded" error came from, as the object was for all intent blank/uninitialised.
    Unless driver not loaded is the default error message for when an Sql object is uninitialised?



  • welcome to devnet

    Good to know that your problem has been solved even so the community was in your case not of much help ;-)

    Special thanks also for sharing the reasons of your problem. This allows at least others to learn from your case.


Log in to reply