QResources relative path problem

  • Hi,
    i want to use windows enviroment variables (a directory) in my QResources. I want to work with a central directory for all my pictures, icons and so on which is referenced by a enviroment variable.

    For example: "c:\bmp" contains all pictures. "BMP = C:\bmp" ist the enviroment variable/value. Is it possible to use this variable in the QResource system? I have read the documentation but couldn't find an anwser.

  • Qt Champions 2016

    It seems only to accept files directly.
    So you would have to add all in C:\bmp / whole folder.

  • Lifetime Qt Champion


    No you can't, the files you put in .qrc must be in the same folder as the .qrc file or in a subfolder within that folder.

    More information here

  • @ck_ee said:

    Is it possible to use this variable in the QResource system?

    As @SGaist said, not directly.

    However, you should be able to add a custom qmake target that creates a symbolic link to the $$(BMP) path under wherever your *.qrc file is.

    As far as I know, qmake has no built-in commands for creating symbolic links, so you'd have to implement per-platform commands; perhaps something like:

    win32-msvc: mybmptarget.commands = mklink /j $$(BMP) $$OUT_PWD/.../resources/bmp
    unix: mybmptarget.commands = ln -s $$(BMP) $$OUT_PWD/.../resources/bmp


  • ty for the tip :]

    finally this .pri file worked for me

    win32 {
        PRJ_DIR = $$OUT_PWD
        PRJ_DIR ~= s,/,\\,g
        BMP_DIR = $$(ENV_PATH)\bmp
        BMP_DIR ~= s,/,\\,g
        mybmptarget.commands = $$(ENV_PATH)\bmp\link.bat $$PRJ_DIR\bmp $$BMP_DIR
        mybmptarget.target = mybmptarget
        QMAKE_EXTRA_TARGETS += mybmptarget
        PRE_TARGETDEPS += mybmptarget

    the link.bat contains:

    if not exist %1 (	
    	mklink /j %1 %2 

    This allows me to use a global ressource folder which is referenced by a PATH variable.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.