我正在尝试通过 qrc 文件将一些 PNG 图标和一些文本文件加载到我在 Qt Creator 中创建的 Qt 程序中,但是当相应的图像出现在 UI 编辑器和 Linux 的工具栏上时(它们应该如此) ,在 Windows 中编译时按钮为空白。我什至尝试过
QImage img(":/icons/debug.png");
qDebug() << img.isNull(); // true
我的源文件和 .pro 文件在 basedir/src/中,资源和 .qrc 文件在 basedir/src/res/中
我做错了什么吗?如果是这样,为什么这在 Linux 中有效但在 Windows 中无效?
编辑:
qDebug() << QImageReader::supportedImageFormats(); // ("bmp", "cur", "dds", "gif", "icns", "ico", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "svg", "svgz", "tga", "tif", "tiff", "wbmp", "webp", "xbm", "xpm")
这是我的 qrc 文件。
<RCC>
<qresource prefix="/icons">
<file>sphere-icon.png</file>
<file>project-properties.png</file>
<file>debug.png</file>
<file>qsi-icon.png</file>
</qresource>
<qresource prefix="/dictionaries">
<file>Enums.txt</file>
<file>LegacyFunctions.txt</file>
<file>MiniSphereObjects.txt</file>
</qresource>
</RCC>
最佳答案
好吧,我不知道为什么会这样,但是在清理和重建了一百次之后,删除了 .pro.user 文件,删除了我的临时文件夹(我在项目文件中设置这些文件夹以使事情更有条理) , 从项目文件中删除 .qrc 文件引用,然后重新启动,突然一切正常
关于c++ - 为什么 Qt 资源在 Linux 而不是 Windows 中加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45777271/