Including resource files in Qt Creator build directory

前端 未结 3 1430
生来不讨喜
生来不讨喜 2020-12-30 08:15

I have a project I am working on with Qt Creator and I\'m trying to get it to add my resource files to my build directories (output) automatically. I have the files in the p

相关标签:
3条回答
  • 2020-12-30 08:54

    If you want to automatically copy files into a directory after the build you can use a post build target.

    In your pro file:

    win32 {
        copyfiles.commands = @call copy <from> <to>
    }
    macx {
        copyfiles.commands = cp <from> <to>
    }
    QMAKE_EXTRA_TARGETS += copyfiles
    POST_TARGETDEPS += copyfiles
    

    Instead of copy <from> <to> you can obviously call a script/batch file that does more post build steps.

    0 讨论(0)
  • 2020-12-30 08:57

    It's now 2012, and neither of these methods works for me. I get this error:

    mingw32-make[1]: Leaving directory `C:/src/GL-Texture-build-desktop-Qt_in_PATH_Debug'
    /usr/bin/sh: copy: command not found
    mingw32-make[1]: *** [copyfiles] Error 127
    mingw32-make: *** [debug] Error 2
    00:28:19: The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building/deploying project GL-Texture (target: Desktop)
    When executing step 'Make'
    

    Looking at the message, I am amazed to see that is using the sh shell, probably because of mingw. Anyhow I solved this problem by using the unix equivalent:

    CONFIG(release, debug|release) {
        DESTDIR = release
    } else {
        DESTDIR = debug
    }
    
    #for Windows
    win32 {
        copyfiles.commands += @echo NOW COPYING ADDITIONAL FILES &
        copyfiles.commands += cp -r ../$${TARGET}/textures $${DESTDIR}/
    }
    
    QMAKE_EXTRA_TARGETS += copyfiles
    POST_TARGETDEPS += copyfiles
    

    This happens on Windows 7 / QT 4.6.3.

    0 讨论(0)
  • 2020-12-30 08:59

    Check out the Qt Resource System.

    To add the resource file into your project, you have add the following in your .pro file..

    RESOURCES = application.qrc

    Detailed examples available in the Qt Docs..

    Once added into the pro file, a separate .qrc file will be added into your Qt project with which you can double click and add your desired resources like icons, translation files etc.,

    Hope it helps..

    0 讨论(0)
提交回复
热议问题