Microsoft Visual Studio:在Qt应用程序中加载资源(无插件) [英] Microsoft Visual Studio: Loading resources in Qt application (without plug-in)

查看:404
本文介绍了Microsoft Visual Studio:在Qt应用程序中加载资源(无插件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们没有为MSVS安装Qt插件,这让我想知道如何/是否可以向应用程序加载资源(图像等).

解决方案

是的,您可以加载资源. 不幸的是,用于创建qrc文件的qrc编辑器是用于VS的Qt插件的一部分...
但是您可以手动创建此xml文件,有关格式,请参见此处
创建qrc文件后,您至少有两种可能性:

A)使用qmake

  1. 在pro文件中添加对您的qrc文件的引用:

    RESOURCES = ApplicationResources.qrc

  2. 通过使用qmake从专业人士重新生成vcproj

    qmake -tp vc

B)如果您不从专业文件中生成vcproj文件,则可以:

  1. 在解决方案中手动添加您的qrc文件,例如在以下路径中:

    资源文件/Res/ApplicationResources.qrc

  2. 在Visual Studio的qrc文件的属性中添加以下命令:
    命令行:$(QTDIR)\ bin \ rcc.exe -name ApplicationResources res \ ApplicationResources.qrc -o $(IntDir)\ qrc__ ApplicationResources.cpp
    说明:RCC资源/ApplicationResources.qrc
    输出:$(IntDir)\ qrc__ ApplicationResources.cpp

C)您还可以使用外部二进制资源文件
命令行:rcc -binary myresource.qrc -o myresource.rcc

在应用程序中,您必须注册资源文件: QResource :: registerResource("/path/to/myresource.rcc");

有关在源代码中使用资源文件的信息,请参见 doc

但是,像cheez一样,我也建议使用qmake和pro文件,不要在Visual Studio中手动编辑属性...

希望这会有所帮助!

We don't have a Qt plug-in installed for MSVS, and it makes me wonder how/whether it is possible to load resources (images, etc) to the application.

解决方案

Yes, you can load ressources. Unfortunately, the qrc Editor which create qrc files is part of the Qt Addin for VS...
But you can create this xml file by hands, for the format see here
Once the qrc file created, you have at least two possibilities :

A) Use qmake

  1. Add a reference to your qrc file in your pro file :

    RESOURCES = ApplicationResources.qrc

  2. Regenerate your vcproj from your pro by using qmake

    qmake -tp vc

B) If you don't generate your vcproj file from your pro file, you can :

  1. Add manually your qrc file in your solution, for example in the following path :

    Resource Files/Res/ApplicationResources.qrc

  2. Add the following commands in the properties of the qrc file in visual studio :
    command line : $(QTDIR)\bin\rcc.exe -name ApplicationResources res\ ApplicationResources.qrc -o $(IntDir)\qrc__ ApplicationResources.cpp
    Description : RCC res/ApplicationResources.qrc
    Output : $(IntDir)\qrc__ ApplicationResources.cpp

C) You can also use an external binary resources file
The command line :rcc -binary myresource.qrc -o myresource.rcc

In the application, you have to register the resource file : QResource::registerResource("/path/to/myresource.rcc");

For using resource file in the source code see the doc

However, like cheez, I also suggest using qmake and pro file and do not edit properties by hand in Visual Studio...

Hope this helps !

这篇关于Microsoft Visual Studio:在Qt应用程序中加载资源(无插件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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