Access resources using qrc file
-
Hello ! :)
I'm currently using a qrc file to load a music file. But when I give the path to an external lib (FMOD), it does not find the file.
FMOD_System_CreateStream(system, QUrl(":/sounds/ocean.mp3").path().toStdString().c_str(), FMOD_DEFAULT, 0, &sound); // File not found QMediaPlayer *player = new QMediaPlayer; player->setMedia(QUrl(":/sounds/ocean.mp3")); // OK player->play();
Do the paths of type :/prefix/alias work only with Qt classes ??
Thanks ! ;) -
@Maluna34 said in Access resources using qrc file:
Do the paths of type :/prefix/alias work only with Qt classes ??
of course they do only work with Qt.
It's just an abstraction layer before the actual file access (via Qt classes) happens. -
@raven-worx
Thanks !! And is it possible to convert them to local paths to be used by other libs ? -
@Maluna34
since they are compiled into your binary and can only be accessed by Qt classes ... noBut on what basis do you want to provide the data to other libs?
For example you could define an interface which returns the binary data of your resource. -
@Maluna34 maybe the qrc file mechanism is not the best approach for what you intend to use; however you only know your actual requirements.
From documentation about Qt resource system:The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable. This is useful if your application always needs a certain set of files (icons, translation files, etc.) and you don't want to run the risk of losing the files.
so a music file for a whole opera concert is not a suitable candidate for being stored in the qrc file as it ends up into your executable.
Given that said, you could get the file from the resource and save it somewhere to disk so the external tool can access it.
QFile::copy(":/sounds/ocean.mp3", "/tmp/ocean.mp3");
you can even use QTemporaryFile to avoid worrying about file naming and deletion.