Qt 应用程序中未加载嵌入式 JPG 资源 [英] Embedded JPG resources not loading in Qt application

查看:42
本文介绍了Qt 应用程序中未加载嵌入式 JPG 资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Qt 应用程序,其中有一些我想要显示的嵌入式 JPG 文件.当我在我的机器上编译并运行调试版本和发布版本时,一切正常.当我将应用程序复制到拇指驱动器并在我的机器上从那里运行它时,它工作正常.在 U 盘和另一台开发人员的机器上:好的.在第三台非开发人员机器上的 U 盘上:没有图像

I have a Qt application that has some embedded JPG files that I want to display. When I compile and run both the debug and release versions on my machine, everything works perfectly. When I copy the application to a thumb drive and run it from there on my machine, it works fine. On the thumb drive and another developer's machine: OK. On the thumb drive on a third, non-developer's machine: no images!

proj.pri
RESOURCES += ./proj.qrc

proj.qrc:
<RCC>
<qresource prefix="/myApp">
    <file>Gui/Resources/logo.jpg</file>
    <file>Gui/Resources/another_image.jpg</file>
</qresource>
</RCC>

main.cpp:
{
    ...
    QImage *logo  = new QImage( ":/myApp/Gui/Resources/logo.jpg" );
    QImage *image = new QImage( ":/myApp/Gui/Resources/another_image.jpg" );

    myClass *d1 = new myClass( "Some Text", 48, 30, logo );
    myClass *d2 = new myClass( "Some More Text", 48, 30, another_image );
    ...
}

我已通过注释掉 .pri 文件中的 RESOURCES 行确认图像已添加到可执行文件中.二进制文件的大小减少了图像的大小加上一点;当我运行应用程序时,图像不会出现.我取消注释 RESOURCES 行,一切都按上述方式工作.

I have confirmed that the images are being added to the executable by commenting out the RESOURCES line in the .pri file. The size of the binary drops by the size of the images plus a bit; when I run the application, the images do not appear. I un-comment the RESOURCES line and everything works as described above.

我在这里错过了什么?非开发人员机器上的 DLL?一个

What am I missing here? A DLL on the non-developer's machine? A

环境:

  • Win XP
  • Qt 4.6.1
  • Visual Studio 2008
  • Qt Creator 1.3.1

推荐答案

需要 jpeg 插件来加载图片.如果您安装了 Qt,它们将位于 %QTDIR%pluginsimageformats 中.

It needs jpeg plugin to load images. If you have Qt installed they would be in %QTDIR%pluginsimageformats.

将 qjpeg4.dll 复制到 U 盘上的插件文件夹中.

Copy qjpeg4.dll into plugin folder on your thumb drive.

root/app.exe
root/qt.conf
root/plugins/imageformats/qjpeg4.dll

在 qt.conf 文件中设置你的插件目录的路径:

In qt.conf file set path to your plugins dir:

[Paths]
plugins=./plugins

这篇关于Qt 应用程序中未加载嵌入式 JPG 资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆