how to play a wav file that is defined in resource file
eveyrthing is old in google search, and
What's your Qt version ?
On what OS ?
It was clearly not possible to do so in earlier Qt versions, see: https://bugreports.qt.io/browse/QTBUG-9253
I cannot tell you if that has changed, though.
From a quick look at the sources of QSound, it seems to still be the case, but it can be worked around using QTemporaryFile for example.
auto player = new QMediaPlayer(this); player->setMedia(QUrl::fromLocalFile(QTemporaryFile(":/sounds/sound1").fileName())); player->play();
doesn't work though
I guess you will have to create a temp file, copy the contents from the resource file to the temp file and then open the temp file.
You can get some inspiration from here: http://www.qtcentre.org/threads/18644-QSound-and-embedded-resources
but I would not take it directly as it does not seem to operate on a temp directory. and operating on the program directory is forbidden on most operating systems.
Hi again @user4592357
In case you are still interested, I just tried myself and a simple
QSound::play(":/claves.wav");did work for me.
There was no need to create temporary files.
I've created a documentation update: https://codereview.qt-project.org/224476 to explicitely state that playing from resources is possible nowadays.