使用PyQt4写了一个小程序,其中用到了sqlite数据库,在我的调试环境中一切正常。当我使用cx_Freeze将其打包后,在运行相应的exe时,出现问题,老是提示"sqlite driver not loaded"的错误,看来是没有找到sqlite对应的驱动。于是百度+google了一番,发现有这样问题的人还不少,其出现这种错误的原因很简单,就是缺DLL库了。cx_Freeze已经将sqlite3.dll、qtsql4.dll拷贝到工作目录下,但是QT本身的数据库驱动qsqlite4.dll没有。于是我搜到了一个qsqlite4.dll文件,将其直接考到工作目录下,运行,仍然报错。于是在深入的研究了一下,发现所谓的数据库驱动,在qt里属于plugins,这些插件在打包发布的时候,必须放置在工作目录的特定文件夹下面,比如数据库驱动要放在"sqldrivers"目录下,并且要小写。如下表所示:
Base Class | Directory Name | Key Case Sensitivity |
---|---|---|
QAccessibleBridgePlugin | accessiblebridge | Case Sensitive |
QAccessiblePlugin | accessible | Case Sensitive |
QDecorationPlugin | decorations | Case Sensitive |
QIconEnginePlugin | iconengines | Case Insensitive |
QImageIOPlugin | imageformats | Case Sensitive |
QInputContextPlugin | inputmethods | Case Sensitive |
QKbdDriverPlugin | kbddrivers | Case Sensitive |
QMouseDriverPlugin | mousedrivers | Case Sensitive |
QPictureFormatPlugin | pictureformats | Case Sensitive |
QScreenDriverPlugin | gfxdrivers | Case Sensitive |
QScriptExtensionPlugin | script | Case Sensitive |
QSqlDriverPlugin | sqldrivers | Case Sensitive |
QStylePlugin | styles | Case Insensitive |
QTextCodecPlugin | codecs | Case Sensitive |
主要参考了:http://www.cuteqt.com/blog/?p=1002 带着插件一起走
http://www.cuteqt.com/blog/?p=1059 带着插件一起走续篇
http://doc.qt.nokia.com/4.3/plugins-howto.html How to Create Qt Plugins
http://doc.qt.nokia.com/4.3/qt-conf.html Using qt.conf