How to set up FMOD Engine with Qt6 MinGW 64-bit

This is my simple project for Qt6 MinGW 64-bit that plays the OGG audio file on Windows: play-audio-from-resources-fmod-qt6-cpp.zip (2.77 MB) You can download it and experiment with the relative set up file. There is the libs folder with FMOD 2.2.21 inside of the project folder. I want to run it without manual copying of fmod.dll to the Debug folder. You can create the libs folder on your hard drive and copy my contains of ‘libs’ folder to it to check that absolute set up path doesn’t require manual copying of fmod.dll to the Debug folder. You should to uncomment the absolute set up path and comment the relative path (don’t forget to change a name of hard drive):

play-audio-from-resources-fmod-qt6-cpp.pro:

QT += core gui widgets

CONFIG += c++17

# The absolute set up FMOD path
# Works without manual copying of fmod.dll to the Debug folder
# INCLUDEPATH += "E:/libs/fmod-2.2.21-mingw-64-bit/include"
# LIBS += -L"E:/libs/fmod-2.2.21-mingw-64-bit/lib/x64/"
# LIBS += -lfmod

# The relative set up FMOD path
# Requires manual copying of fmod.dll to the Debug folder
INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include
LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64
LIBS += -lfmod

# Using fmod_vc.lib
# Requires manual copying of fmod.dll to the Debug folder
# INCLUDEPATH += $$PWD/libs/fmod-2.2.21-mingw-64-bit/include
# LIBS += $$PWD/libs/fmod-2.2.21-mingw-64-bit/lib/x64/fmod_vc.lib

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# Disables all the APIs deprecated before Qt 6.0.0
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000

SOURCES += \
    main.cpp \
    widget.cpp

HEADERS += \
    widget.h

RESOURCES += \
    assets.qrc

widget.h

#ifndef WIDGET_H
#define WIDGET_H

#include <QtWidgets/QWidget>
#include <fmod.h>

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private:
    FMOD_SYSTEM *m_system;
    FMOD_SOUND *m_sound;
};

#endif // WIDGET_H

widget.cpp

#include "widget.h"

#include <QtCore/QByteArray>
#include <QtCore/QFile>
#include <QtCore/QString>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    FMOD_System_Create(&m_system, FMOD_VERSION);
    FMOD_System_Init(m_system, 32, FMOD_INIT_NORMAL, 0);

    QString soundPath(":/assets/audio/overworld.ogg");
    QFile f(soundPath);
    if (!f.open(QIODevice::OpenModeFlag::ReadOnly))
    {
        qDebug() << "Faild to open the file: " << soundPath;
        return;
    }
    QByteArray soundData = f.readAll();
    f.close();

    FMOD_CREATESOUNDEXINFO* exinfo = new FMOD_CREATESOUNDEXINFO();
    exinfo->length = static_cast<unsigned int>(soundData.length());
    exinfo->cbsize = sizeof(FMOD_CREATESOUNDEXINFO);
    FMOD_System_CreateSound(m_system, soundData.data(), FMOD_OPENMEMORY, exinfo, &m_sound);

    FMOD_Sound_SetMode(m_sound, FMOD_LOOP_OFF);

    FMOD_System_PlaySound(m_system, m_sound, 0, false, 0);
}

Widget::~Widget()
{
    delete m_system;
    delete m_sound;
}

main.cpp

#include "widget.h"

#include <QtWidgets/QApplication>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    Widget w;
    w.show();
    return app.exec();
}

assets.qrc

<RCC>
    <qresource prefix="/">
        <file>assets/audio/overworld.ogg</file>
    </qresource>
</RCC>