无法打开资源文件 [英] Cannot open resource file

查看:73
本文介绍了无法打开资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

QFile test("://needle.png"); // also tried :/needle.png :\needle.png :\\needle.png

if(test.open(QFile::ReadOnly)) {
    qDebug() << "yay";
} else {
    qDebug() << "fail";
}

我的项目文件中有这个:

I have this in my project file:

RESOURCES += Resources.qrc

这是我的 QRC 文件:

Here is my QRC file:

<RCC>
    <qresource prefix="/">
        <file>needle.png</file>
    </qresource>
</RCC>

我的输出总是失败.有什么想法吗?

I keep getting fail as output. Any ideas?

推荐答案

是否使用 URL 表示法

Does the URL notation

QFile test("qrc:///needle.png");

为你工作?

这篇关于无法打开资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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