6

I am using Qt Creator and I have created a resource file. When I try to access the resource file when I am in designer mode, it says that resource root is empty.

How can I specify the resource dir? How come it does not appear if it is in the same folder?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sara
  • 833
  • 2
  • 9
  • 21

3 Answers3

1

For using resource file even if it is situated in the same folder, you have to add the resource file to the project in Qtcreator for using it. Just right click on the project name on the tree view of your project in QtCreator and click on add existing files, then you add your resource file and now you can use your resource in your project.

By adding it this way, it will be added to you project. Or you can register resources to project explicitly with

 QResource::registerResource("/path/yourresource.rcc");

You can specify resource directory using :/ prefix or qrc:///.

For ex:qrc:///files/yourfile will get you to the yourfile situated in files in your added resource.

ScarCode
  • 3,074
  • 3
  • 19
  • 32
  • I have created the source file with Qt creator, and it appears on the list of sources. So I think it is already included in the project. – Sara May 21 '12 at 06:48
  • 1
    I have .qrc file added in .pro and can edit it from Qt Creator, but it is still not accessible in Qt Designer – rkudinov May 06 '20 at 07:50
0

For those who come here looking for how to access a .qrc Resource File in Qt Creator on OS X, try opening your UI file in Qt Designer first (NOT Qt Creator). When you look for a resource in Qt Designer you have the option to add a new .qrc resource file (This option doesn't exist in Qt Creator for me). Add the .qrc resource file, save, close, and reopen in Qt Creator. The resource file will now be available for all images.

Joe Cat
  • 179
  • 1
  • 8
0

You can also modify CMakeLists.txt and add the resource file:

qt_add_executable(ProjectName
Resources.qrc
${PROJECT_SOURCES}
)

Source: The Qt Resource System