手动和动态加载标准 qt 插件
谁能提供一个如何手动加载 qjpeg 或任何其他标准 QT 插件的示例。请给出一个代码示例,而不是指向 qt 页面的链接,因为我已经知道以下事实:
- 我没有将 qt 链接为静态库。
- 我知道如何部署标准 qt 插件(这是自动部分) 2.1.对于 qjpeg,您将 qjpeg4.dll 复制到 ./imageformats/qjpeg4.dll 作为 .作为基本目录 您的应用程序的。 但我想加载并使用 qjpeg lib。
因为
QPluginLoader loader("qjpeg4.dll");
if (loader.instance()) {
cout << "ok" << endl;
} else {
cout << "fail" << endl << loader.errorString().toStdString() << endl;
}
QList<QByteArray> list = QImageReader::supportedImageFormats();
for (int i = 0; i < list.size(); ++i) {
f << list.at(i).constData() << std::endl;
}
这里不打印 jpg 并且无法读取和写入 jpg 图像。也许如果有人在这里添加更多东西它会起作用。或者也许我完全错了。
Can anyone please give an example of HOW TO LOAD qjpeg or any other standard QT plugin manually. Please give a CODE EXAMPLE, Not a link to qt pages because I already know the following facts:
- I am not linking qt as static lib.
- I know how to deploy standard qt plugins (this is the automatic part)
2.1. for qjpeg you copy qjpeg4.dll to ./imageformats/qjpeg4.dll as . being the base dir
of your app.
but I want to load and use qjpeg lib.
as in
QPluginLoader loader("qjpeg4.dll");
if (loader.instance()) {
cout << "ok" << endl;
} else {
cout << "fail" << endl << loader.errorString().toStdString() << endl;
}
QList<QByteArray> list = QImageReader::supportedImageFormats();
for (int i = 0; i < list.size(); ++i) {
f << list.at(i).constData() << std::endl;
}
this does not print jpg and jpg images cannot be read and written. Maybe if someone adds something more here it will work. or maybe I am copletely wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有这样做,但这是一个有根据的猜测,您可能正在做正确的事情来加载插件,但如果不走正常路线,
QImageReader
实际上并不知道该插件可用。如果您确实需要显式加载插件,您可以将QPlugiLoader::instance()
的结果转换为QImageIOPlugin
并使用QIOImageHandler
> 读取您的 jpg,但看起来您必须放弃使用QImageReader
I haven't done this but here is an educated guess, you are probably doing the right thing to load the plugin but by not going the normal route the
QImageReader
does not actually know about the plugin being available. If you really need to explicitely load you plugin, you can probably cast the result ofQPlugiLoader::instance()
to aQImageIOPlugin
and using theQIOImageHandler
to read your jpgs, but it looks like you would have to forgo using theQImageReader