简体   繁体   English

Microsoft Visual Studio:在Qt应用程序中加载资源(无插件)

[英]Microsoft Visual Studio: Loading resources in Qt application (without plug-in)

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

Yes, you can load ressources. 是的,您可以加载资源。 Unfortunately, the qrc Editor which create qrc files is part of the Qt Addin for VS... 不幸的是,创建qrc文件的qrc编辑器是Qt Addin for VS的一部分......
But you can create this xml file by hands, for the format see here 但你可以手工创建这个xml文件,格式见这里
Once the qrc file created, you have at least two possibilities : 创建qrc文件后,您至少有两种可能性:

A) Use qmake A) 使用qmake

  1. Add a reference to your qrc file in your pro file : 在pro文件中添加对qrc文件的引用:

    RESOURCES = ApplicationResources.qrc RESOURCES = ApplicationResources.qrc

  2. Regenerate your vcproj from your pro by using qmake 使用qmake从您的专业版重新生成您的vcproj

    qmake -tp vc qmake -tp vc

B) If you don't generate your vcproj file from your pro file, you can : B) 如果您没有从pro文件生成vcproj文件,您可以:

  1. Add manually your qrc file in your solution, for example in the following path : 在解决方案中手动添加qrc文件,例如在以下路径中:

    Resource Files/Res/ApplicationResources.qrc 资源文件/ Res / ApplicationResources.qrc

  2. Add the following commands in the properties of the qrc file in visual studio : 在visual studio中的qrc文件的属性中添加以下命令:
    command line : $(QTDIR)\\bin\\rcc.exe -name ApplicationResources res\\ ApplicationResources.qrc -o $(IntDir)\\qrc__ ApplicationResources.cpp 命令行 :$(QTDIR)\\ bin \\ rcc.exe -name ApplicationResources res \\ ApplicationResources.qrc -o $(IntDir)\\ qrc__ ApplicationResources.cpp
    Description : RCC res/ApplicationResources.qrc 描述 :RCC res / ApplicationResources.qrc
    Output : $(IntDir)\\qrc__ ApplicationResources.cpp 输出 :$(IntDir)\\ qrc__ ApplicationResources.cpp

C) You can also use an external binary resources file C) 您还可以使用外部二进制资源文件
The command line :rcc -binary myresource.qrc -o myresource.rcc 命令行:rcc -binary myresource.qrc -o myresource.rcc

In the application, you have to register the resource file : QResource::registerResource("/path/to/myresource.rcc"); 在应用程序中,您必须注册资源文件:QResource :: registerResource(“/ path / to / myresource.rcc”);

For using resource file in the source code see the doc 要在源代码中使用资源文件,请参阅doc

However, like cheez, I also suggest using qmake and pro file and do not edit properties by hand in Visual Studio... 但是,像cheez一样,我也建议使用qmake和pro文件,不要在Visual Studio中手动编辑属性...

Hope this helps ! 希望这可以帮助 !

Use the qrc executable to generate a cpp file which you can include in your project: 使用qrc可执行文件生成一个cpp文件,您可以将其包含在项目中:

/usr/local/Trolltech/Qt-4.5.1/bin/rcc -name core core/core.qrc -o build/release/core/qrc_core.cc /usr/local/Trolltech/Qt-4.5.1/bin/rcc -name core core / core.qrc -o build / release / core / qrc_core.cc

See http://doc.trolltech.com/4.0/resources.html 请参见http://doc.trolltech.com/4.0/resources.html

However, I strongly suggest using qmake or some other build system to automate this for you. 但是,我强烈建议使用qmake或其他一些构建系统为您自动执行此操作。

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

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