Qt:自定义的sqldrivers dll(QtCipherSqlitePlugin)无法加载,提示sqlitecipher.dll is not a Qt plugin (metadata not found)

自定义的sqldrivers dll无法加载。添加测试代码:

	qDebug() << "sqlite drivers: " << QSqlDatabase::drivers();

	QString driverPath = QCoreApplication::applicationDirPath() + "/sqldrivers/sqlitecipher.dll";
	auto l = QPluginLoader(driverPath);
	if (!l.load()) {
		qDebug() << "Failed to load SQLite DLL:" << driverPath;
		qDebug() << "Error:" << l.errorString();
	}
	qDebug() << "sqlite drivers: " << QSqlDatabase::drivers();

返回错误提示: sqlitecipher.dll is not a Qt plugin (metadata not found)

比对代码发现,因为此前无法编译通过,误删了关键的metadata代码:

Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "SqliteCipherDriverPlugin.json")

恢复此行代码,并删除#if (QT_VERSION >= 0x050000)的版本判断,否则还会提示以下错误:

1> QtCipherSqlitePlugin\src\main.cpp: note: No relevant classes found. No output generated.
1>main.cpp
1>main.obj : error LNK2001: 无法解析的外部符号 "public: virtual struct QMetaObject const * __cdecl SqliteCipherDriverPlugin::metaObject(void)const " (?metaObject@SqliteCipherDriverPlugin@@UEBAPEBUQMetaObject@@XZ)
1>main.obj : error LNK2001: 无法解析的外部符号 "public: virtual void * __cdecl SqliteCipherDriverPlugin::qt_metacast(char const *)" (?qt_metacast@SqliteCipherDriverPlugin@@UEAAPEAXPEBD@Z)
1>main.obj : error LNK2001: 无法解析的外部符号 "public: virtual int __cdecl SqliteCipherDriverPlugin::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SqliteCipherDriverPlugin@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)

提示 SqliteCipherDriverPlugin.json 文件找不到,修改:

Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "src/SqliteCipherDriverPlugin.json")

问题解决。

 

 

转载请注明来源,谢谢。

有偿解决C++编程问题,承接项目定制开发;寻一份全职或兼职Windows C++开发工作。联系邮箱:[email protected]


老刀的技术日志 » Qt:自定义的sqldrivers dll(QtCipherSqlitePlugin)无法加载,提示sqlitecipher.dll is not a Qt plugin (metadata not found)

发表评论