如何在没有 Qt 项目的情况下在 Visual Studio 中使用 Qt 资源文件?

编程入门 行业动态 更新时间:2024-10-25 13:28:17
本文介绍了如何在没有 Qt 项目的情况下在 Visual Studio 中使用 Qt 资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想在我的程序中使用 Qt 的资源系统.Visual Studio 的资源系统在加载 .png、.bmp、.jpeg 等非基于文本的文件时让我头疼.我读过一些关于 Qt 的文章,看起来很有趣.我想使用它的资源系统.我已经下载了 Qt Visual Studio Tool 扩展.我还制作了一个资源文件,其中包含我想嵌入到可执行文件(不是 Qt 的可执行文件)中的文件.我做了一个 Visual Studio 项目,而不是 Qt 项目.我安装扩展的唯一原因是将资源嵌入到我的可执行文件中并访问它们.另外,如果可能的话,我想在我的非 Qt 项目中包含 Qt 的头文件,这样我就可以轻松地注册和阅读这些资源.所以,简而言之,这就是我想要做的:

I want to use Qt's resource system for my program. Visual Studio's resource system is giving me headaches while loading non text based files like .png, .bmp, .jpeg, etc. I have read a bit about Qt and it seems very interesting. I would like to use its resource system. I have downloaded the Qt Visual Studio Tool extension. I have also made a resource file containing the files that I would like to embed in the executable (NOT Qt's executable). I have made a Visual Studio Project, NOT a Qt Project. The only reason I installed the extension is to embed the resources in my executable and access them. Also, if possible I would like to include Qt's headers in my non-Qt Project, so I can easily register and read those resources. So, in a nutshell, this is what I want to do:

使用 Qt 将我的资源嵌入到可执行文件中.在我的程序中访问这些文件.

像这样:

#include <Qtheaderfiles>

struct FileData {
    unsigned char* bytes;
    unsigned int size;
};

FileData loadFromResource(const std::string& res) {
    QtFile file(res);

    //get all the data from the file and return it in bytes.
    return FileData { fileBytes, fileSize };
}

即使res"目录中没有实际文件,我也希望上述代码能够编译,因为所有资源都已嵌入到可执行文件中.

I expect the above code to compile even when there is no actual file in the directory "res", because all of the resources have been embedded into the executable.

推荐答案

略读 Qt资源文档:

创建一个 .qrc 文件,其中包含您想要包含的资源列表创建一个自定义构建步骤,在该文件上调用 rcc (文档)编译生成的 cpp 源文件并将其链接到您的程序中. Create a .qrc file that contains a list of the resources you would like to include Create a custom build step that invokes rcc on that file (documentation) Compile and link the resulting cpp source file into your program.

这篇关于如何在没有 Qt 项目的情况下在 Visual Studio 中使用 Qt 资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 13:28:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154930.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   文件   项目   如何在   资源

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!