QT5.2资源文件
QT5.2 Resource files
简短而烦人的问题;我无法访问QT资源文件(又称.QRC)中定义的任何内容。我遵循了QT UTOARIAL创建一个名为TextFinder的窗口小部件应用程序。根据它,我创建了所有必要的文件并完成了所有指令,但我无法访问QRC内容。 在项目文件夹中,我有例如:
TextFinder
resources
input.txt
main.cpp
textfinder.cpp
textfinder.h
TextFinder.pro
TextFinder.pro.user
TextFinder.qrc
textfinder.ui
QRC文件的内容如下:
<RCC>
<qresource prefix="/res">
<file>resources/input.txt</file>
</qresource>
</RCC>
要访问我内部的文件,我在编辑器中打开了QRC,请单击该文件,然后选择复制资源路径到剪贴板选项。这产生了":/res/resources/input.txt"。因此,我刚将其输入我的功能以打开文件。此功能看起来如下:
void TextFinder::loadTextFile()
{
QFile inputFile(":/res/resources/input.txt");
inputFile.open(QIODevice::ReadOnly);
if (inputFile.isOpen())
{
QTextStream txtStream(&inputFile);
QString contents = txtStream.readAll();
inputFile.close();
ui->textEdit->setPlainText(contents);
QTextCursor cursor = ui->textEdit->textCursor();
cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1);
}
else
{
throw std::runtime_error("Resource file may be wrong?");
}
}
当我运行应用程序时,runtime_error被抛出,告诉我它无法打开文件。在项目文件中,我的QRC文件定义如下:
RESOURCES +=
TextFinder.qrc
这里出了什么问题?有人可以指出我做错了什么?
问候, 乔
根据QT资源系统文档:
也可以使用QResource标签的前缀属性指定.QRC文件中所有文件的路径前缀:
<qresource prefix="/myresources"> <file alias="cut-img.png">images/cut.png</file> </qresource>
在这种情况下,该文件可访问为:/myresources/cut-img.png。
因此,在存在前缀时剪切了
相关文章:
- 具有瞬态资源的RAII类
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 允许从 std::map 的密钥窃取资源?
- 为测试目标创建具有不同源文件夹的文件
- 参考资源文件VC++中的$(SolutionDir)
- 如何维护资源管理器项目视图中当前可见的项目列表
- 将图像添加到资源文件夹UWP C++
- 将 std::allocate_shared 与多态资源分配器一起使用
- 使用RAII在给定次数的迭代后重新分配资源
- 资源管理设计模式
- 视觉工作室项目.提取源文件夹名称
- 如何跨平台将二进制资源构建到程序中?
- 生成一个生成文件,该生成文件使用Automake在一个步骤中编译和链接所有源文件
- SetDlgItemInt 不会更改嵌入资源的编辑框
- Klocwork Inside的资源泄漏
- make 命令如何避免重新编译未更改的源文件?
- C++两个源文件之间共享的枚举的静态实例
- Windows 资源源文件中 #define 的含义
- 如何让资源黑客在.rc源文件上工作
- 在cmake目标的解决方案资源管理器中添加一些源文件的头依赖项