Nominate our 2022 Qt Champions!

[SOLVED] Use qrc file from CMake

  • I use CMake to organise my project. And I have some resource files (qml, png) within my application.

    I want to avoid to list resource files twice: in CMakeLists.txt and qrc file, therefore:

    • Added all resource files to qrc file
    • Wrote a cmake macro to parse the qrc file to see all resource files in QtCreator too

    So please comment what you think about this approach.


  • Lifetime Qt Champion


    Why not use

    @qt5_add_resources(UI_RESOURCES myresources.qrc)




  • Possible I miss this aspect in my initial post, but do you see the files used in myresources.qrc in QtCreator's Project view? I do not. So I have to navigate through myresources.qrc. Not very handy from my point of view.

  • Lifetime Qt Champion

    I'm not sure I'm following you correctly. Do you mean see the files themselves or the qrc file ?

  • I want to see both, myresources.qrc file and all files listed in it.
    But in the meantime I implemented another approach:
    List all the resources in a CMakeLists.txt and during build the myresources.qrc is generated and used as input for rcc tool.

  • Lifetime Qt Champion

    AFAIK, even with qmake you would need to add the files as OTHER_FILES if you want to have them shown both separately

Log in to reply