我的qt程序中加了一个例子代码,如下:
- C/C++ code
static bool createConnection(){ QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":memory:"); if (!db.open()) { QMessageBox::critical(0, "Cannot open database", "Unable to establish a database connection.\n" "This example needs SQLite support. Please read " "the Qt SQL driver documentation for information how " "to build it.\n\n" "Click Cancel to exit.", QMessageBox::Cancel); return false; }}
在一个没有装qt环境的机器上运行就打不开数据库,提示QMessageBox中的内容,窗体是可以出现的,我网上查了有的说把数据库驱动拷进去就可以了,我把plugins/sqldrivers 全部都拷进去了还是不行,想了各种方法都不行。求求大家了!
------解决方案--------------------
main函数里加 a.addLibraryPath("plugins/sqldrivers/");