简体   繁体   English

Linux下的Qt资源

[英]Qt Resources under Linux

I want to use Qt Resources file .qrc to load resources to my soft. 我想使用Qt资源文件.qrc将资源加载到我的软件中。 Under Windows, it works perfectly, but under Linux (Ubuntu 12.10), it doesn't work at all. 在Windows下,它可以完美运行,但是在Linux(Ubuntu 12.10)下,它根本不起作用。

Here is a part of my resources.qrc file : 这是我的resources.qrc文件的一部分:

<qresource prefix="/ressources">
    <file alias="style">ressources/style.css</file>
</qresource>

When I open this file in my code I make something like that : 当我在代码中打开该文件时,我将执行以下操作:

QFile file(":/ressources/style.css");

if (!file.open(QIODevice::ReadOnly))
{
    qDebug() << "open fail";
    return ;
}

open() method is unable to open that file properly. open()方法无法正确打开该文件。

Have you an idea ? 你有主意吗?

Thank you. 谢谢。

You've specified "style" as the alias, so you can only open it with: 您已将"style"指定为别名,因此只能使用以下方式打开它:

QFile file(":/ressources/style");

However, since the prefix you specified is identical to the physical directory name, why don't you just do this instead: 但是,由于您指定的前缀与物理目录名称相同,所以为什么不这样做呢?

<qresource>
    <file>ressources/style.css</file>
</qresource>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM