Configuring differents resources with qmake command line

  • Hello,

    I would like to have several resource configurations depending on the projects.
    Only, I would like not to configure the resource paths in the file .pro, for not having specific code in the project.

    I want to pass an argument in qmake to specify the resource

    I thought of two solutions :

    1 - add resources path variable in qmake (like CONFIG+=DEFINES+=MY_PATH=\"C:/../path\"). Use this path for load binaries resources rcc

    2 - add resource configuration in qmake (like CONFIG+=RESOURCES+=pathToRessource)

    I do not know if one of the two solutions is feasible, I did not succeed

    One last solution that works but that I do not want is:
    3 - Add PATH_A{ RESOURCES += path_to_resources_a} in .pro, and in qmake command line add : CONFIG+=PATH_A

    Do you have a solution to do that?



  • Why not using environment variables which can be set before calling qmake in the command line?

    As you can find in the qmake documentation, qmake can evaluate environment vars at runtime.


  • Thanks Karl-Heinz,

    Environment variable solution works for load resource file at runtime

    3 steps :

    • create binarie rcc from qrc resource file : rcc -binary myresource.qrc -o myresource.rcc
    • add env variable MY_PATH=path_to_rcc_file. In qtCreator I do : "project->compilation environment->Add"
    • in source code, we load rcc binary at runtime :
    QString my_path(qgetenv("MY_PATH"));
    QResource::registerResource(path); // with #include <QResource> before

    Only I realize that this is not what I want :(
    I need to be able to load resources when compiling, to distribute only an executable file (and not exe + rcc file)
    So my solution 1- (proposed in the first message) is wrong



  • Thanks
    But, i can't load ressource at runtime. I need to add resource in comiling step as if the resources were added in .pro, but in command line.

  • Lifetime Qt Champion


    I think karlheinzreichel ment you can use env. variable to select what qres to use


    so you can just name it on command line and the qres is then compiled into .exe

  • Thanks mrjj and Karl-Heinz,

    Effectively, it's work!

    In qmake command line add RESOURCES+=$$(RPATH2)
    And declare RPATH2=path in env variable

    It must be possible to do it in a script, I use qtCreator for test

    Resources are well embarked in .exe. (for embarked text ressources, I created .ini file and load it with QSettings)

    I can close topici think


Log in to reply