Search code examples
c++resourcescross-platformqmake

Good practice for implementing resource directories


I'm not sure if this is too general, so if it is I'll say that I'm on Linux using qmake, but I'd like to be able to switch from Linux to Windows with my project whenever I need to, as well as, possibly other PCs.

In order to do this, I'd like to know how some of the programmers on here have gotten around using resource directories without using absolute path definitions. With Qt, it seems like the runtime working directory is the build directory of the application, and not the source directory.

Ideally, I think the best solution would be to somehow get the Resource directory as it resides in the source directory and copy that to the relative build directory (i.e., Debug or Release, depending on development stage) so that the application can access that via run time.

This can introduce some complication, however (at least, I think it can).

Anyway, what would be a good solution to do this?


Solution

  • If you are using Qt. I would suggest using deploy process. http://doc.qt.digia.com/qtcreator/creator-building-running.html

    Basically, you just need to declare which directories need to be copied. The qt creator will copy those dirs to build dir(release/debug) after build process is done.Then you simply run the executable.

    Here is one of example. https://github.com/longwei/incubator-cordova-qt.

    in the pro file

    wwwDir.source = www
    xmlDir.source = xml
    qmlDir.source = qml
    
    DEPLOYMENTFOLDERS = wwwDir xmlDir qmlDir
    

    second

    include(deployment.pri)
    qtcAddDeployment()
    

    then it is done.