Important: Please read the Qt Code of Conduct -

Where to put game sound files?

  • Hello guys,

    I am developing a game and dont know where to put the sound files. If i put it hardcoded in a path, then there is a problem for the installation file. Also, If i put it in the resources, QT does not play wave files from resources also all those files are loaded into memory. Now i am developing for MAC, in mac there is a folder for my and inside it there should be the sound files.
    But what would be the path of the sound file at run time? and how to put the sound files inside the app folder while programming and testing?

    For windows, i can locate it at the same installation folder with ex ./resource/media.wav

    Could any body help me please for Mac

  • but how to put them in the resources of my bundle

  • I am sure there are other ways but this worked for me:

    QMAKE_POST_LINK = mkdir -p $$TARGET".app/Contents/Resources" && cp -Rf $$PWD/folder_with_soundfiles_in_you_sourcedirectoty $$OUT_PWD/$$TARGET".app/Contents/Resources"

  • what is QMAKE? is it a command to be written inside the pro file?
    is it only for deployment or also debugging while development?

  • Specify your media files to deploy with something like:

    mediafolder.source = data/media
    DEPLOYMENTFOLDERS = mediafolder

    Then, at runtime, use QCoreApplication::applicationDirPath() to find your executable's directory and form an absolute path to your media/ directory from that.

    This is what we're doing in our main.cpp for a QtQuick 2.0 project (applies to non-QML project as well):

    QString appdir = QCoreApplication::applicationDirPath();
    qDebug() << "application dir is " << appdir;

    #if defined(MACOSX_BUILD)
    QString filePrefix = "file://" + appdir + "/../Resources/";
    #elif defined(WINDOWS_BUILD)
    QString filePrefix = "file:///" + appdir + "/";
    qDebug() << "filePrefix is " << filePrefix;

    Then in QML code we use it as such:

    Audio {
    id: defaultMusic
    source: filePrefix + "media/theme.m4a"
    autoPlay: true
    loops: Audio.Infinite
    volume: 1.0

    and in the .pro file we have the macro definitions:


    I find it very irritating that media play does not work from a qrc resource. I tried fooling around for an hour with memory-based QIODevice solutions with QMediaPlayer but could not make it work in that timeframe.

    • Matti

  • Hello Matti

    thank you the details but i can not get it to work properly.

    For testing, i made the following :-

    In the Pro file I added

    myFiles.sources = *
    myFiles.path = /Volumes/DATA/gamemedia/
    DEPLOYMENT += myFiles

    then I compile the application from the Creator. I then open Terminal in MAC and get inside the file, and then the Resources folder and don't find the files in it

    Is there something missing?

    Is it Deployment or Deploymentfolders?

  • If you look in the qmake Variable reference, under DEPLOYMENT: it reads

    bq. This is only used on Windows CE and the Symbian platform.

    That doesn't solve your problem, but you should definitely not use DEPLOYMENT on a Mac. Sadly DEPLOYMENTFOLDERS is not even mentioned in the reference :-/

Log in to reply