Microsoft Visual Studio: loading resources into a Qt application (without a plug-in)

We do not have a Qt plug-in for MSVS, and this makes me wonder how / whether resources (images, etc.) can be loaded into the application.

+4
source share
2 answers

Yes, you can download resources. Unfortunately, the qrc editor that creates qrc files is part of the Qt Addin for VS ...
But you can create this xml file by hand, for the format see here
After creating the qrc file, you have at least two possibilities:

A) Use qmake

  • Add a link to your qrc file in your pro file:

    RESOURCES = ApplicationResources.qrc

  • Recover your vcproj from your pro using qmake

    qmake -tp vc

B) If you do not generate your vcproj file from your pro file, you can:

  • Manually add your qrc file to your solution, for example, in the following path:

    Resource Files /Res/ApplicationResources.qrc

  • Add the following qrc file properties properties to 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 resource file
Command line: rcc -binary myresource.qrc -o myresource.rcc

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

To use a resource file in source code, see doc

However, like cheez, I also suggest using the qmake and pro file and not editing the properties manually in Visual Studio ...

Hope this helps!

+11
source

Use the qrc executable to create a cpp file that you can include in your project:

/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

However, I highly recommend using qmake or some other build system to automate this for you.

+2
source

All Articles