QT 关于Driver not loaded 与 结构体的构造函数
2018-02-21 15:23
453 查看
QT 关于Driver not loaded
在程序中使用SQLite数据库,如下的代码:QSqlDatabase db; QSqlQuery query; db = QSqlDatabase::addDatabase("QSQLITE"); if(db.open()){ if(!query.exec("create table student(name text)")){ qDebug()<<query.lastError(); } db.close(); }
总是报错:
Driver not loaded Driver not loaded.
在帮助文档中,查看说明,有这样的话:
Ensure that you are using a shared Qt library; you cannot use the plugins with a static build. Ensure that the plugin is in the correct directory. You can use QApplication::libraryPaths() to determine where Qt looks for plugins. Ensure that the client libraries of the DBMS are available on the system. On Unix, run the command ldd and pass the name of the plugin as parameter, for example ldd libqsqlmysql.so. You will get a warning if any of the client libraries couldn't be found. On Windows, you can use Visual Studio's dependency walker. With Qt Creator, you can update the PATH environment variable in the Run section of the Project panel to include the path to the folder containing the client libraries. Compile Qt with QT_DEBUG_COMPONENT defined to get very verbose debug output when loading plugins.
奇怪,我查看
QApplication::libraryPaths()输出的信息,确信plugin路径正确。动态库文件也存在:
/Users/weiyang/Qt5.9.2/5.9.2/clang_64/plugins/sqldrivers。仔细查看输出,我观察到在此之前还有
QSqlQuery::exec: database not open。
我试着这样改:
QSqlDatabase db; db = QSqlDatabase::addDatabase("QSQLITE"); QSqlQuery query;
先创建好Sqlite connection class,然后创建query对象。OK!
结构体构造函数
假设结构体中包含有参构造函数,如下:typedef struct _Data { int a; string s; _Data(int _a, string _s){ a = _a; s = _s; } }Data;
那么,就不能使用类似于这样的语句:
sentenceUnit senUnit。
C++会尝试匹配
move constructure,
copy constructrue, 有参构造函数。
Data d(1,"hello"); Data d1(d); //copy constructrue Data d2(std::move(d)); //move constructure.
如果这些都没有,那么编译器则会报出不匹配的错误。
我们需要自己写出无参构造函数。
那么如果是类的话,情况是类似的:
class Data { public: int a; string s; Data(int _a, string _s){ a = _a; s = _s; } }; int main() { Data d = Data(1,"hello"); //we can't use 'Data d()', or compiler regard it as a functon. Data d1(d); //copy constructrue Data d2(std::move(d)); //move constructure. Data d3; //error: no matching constructure. return 0; }
相关文章推荐
- 【已解决】Qt 5.7.0 on Ubuntu, MySQL数据库报错 (driver not loaded)
- QT & SQLite - driver not loaded[Win7 XP mode failed too]
- 关于qt的问题构造函数的问题
- ubuntu下 QT 连接各种数据库报错解决(QSqlDatabase: * driver not loaded )
- Qt5.7与MySQL5.7在win10下的连接问题(QMYSQL driver not loaded !)
- 关于QT/C++中explicit关键字和构造函数的*parent参数的简单说明
- Qt开发的sqlite数据库应用出现Driver not loaded
- 编译Qt的mysql驱动及解决 driver not loaded 错误
- 关于Qt开发MySQL程序移植后出现"Driver not loaded"的问题
- 通过QT_DEBUG_PLUGINS调试连接PostgreSQL/MySQL时driver not loaded问题
- ubuntu上 QT 连接各种数据库报错解决(QSqlDatabase: * driver not loaded )
- qt中driver not loaded
- ubuntu上 QT 连接各种数据库报错解决(QSqlDatabase: * driver not loaded )
- QT-MYSQL连接问题( Driver not loaded)
- qt4:mysql驱动程序 driver not loaded
- Qt中编译mysql驱动程序及解决 driver not loaded 错误
- CentOS7 (64位) 下QT5.5 连接MySQL数据库(driver not loaded)
- QT-MYSQL连接问题( Driver not loaded)
- qt 加载 mysql 驱动出错:driver not loaded
- Qt 5.1.0 on Ubuntu Linux, MySQL数据库报错 (driver not loaded)