PDA

View Full Version : QSound and the resource file



dhice
19th March 2009, 21:50
Hi, I'm having trouble getting QSound to play anything other than the default Windows dink. I've tried giving it a hard path, which worked, but I need it to be relative to the current directory.

The source code directory is structured as:

./
./Pics
./Sounds

where all the source code is located in ./

I've tried the following:

QSound::play(":/Sounds/sound.wav");

QSound::play(":Sounds/sound.wav");

QSound::play("Sounds/sound.wav");


//I know the following works
QSound::play("C:/sound.wav");


So my question is what am I doing wrong in regards to playing sound from the current directory?

Thanks

Lykurg
19th March 2009, 22:00
a) "Note that QSound does not support resources. This might be fixed in a future Qt version."

b) maybee a typo, that ":" should be "."

c) use QDir to generate an absolute path

d) Current_working_directory (http://wiki.qtcentre.org/index.php?title=Current_working_directory) could be helpful

dhice
19th March 2009, 22:19
a) "Note that QSound does not support resources. This might be fixed in a future Qt version."

b) maybee a typo, that ":" should be "."

c) use QDir to generate an absolute path

d) Current_working_directory (http://wiki.qtcentre.org/index.php?title=Current_working_directory) could be helpful


Thank you for the information, I followed your suggestions and it works like a charm.

Markus
9th January 2011, 21:15
Hi dhice,

I see you got the problem solved but I still don't know how it works. DO you have to create a temp file?
could you post your source on how to play a sound off a resource file?

Thanks
Markus

pip010
19th May 2017, 14:49
Yes, please, someone please give a clear example of sucha basic thing anyone expects ..... :(

d_stranz
19th May 2017, 17:25
How much more clear does it need to be? As Lykurg said, QSound can only play content from files on disk, it cannot play sounds encoded in the program's resources.



//I know the following works
QSound::play("C:/sound.wav");


You need to give QSound the name of a disk file that has sound encoded in .wav format, and the file needs to be able to be found at run time - either it is in the program's current working directory or the location is specified using an absolute path (like the example above).

Lesiok
19th May 2017, 17:30
How much more clear does it need to be? As Lykurg said, QSound can only play content from files on disk, it cannot play sounds encoded in the program's resources.Sorry d_stranz, You're wrong. Maybe it was true 8 years ago (the thread is from 2009). Today QSound plays files from resources with no problems. I use this in several applications.

d_stranz
19th May 2017, 17:42
Sorry d_stranz, You're wrong.

My mistake. I'm looking at the docs for Qt 5.4 and it doesn't mention resource files at all, only "sound files", and the examples in the docs use disk file names, not resource file names. So it seemed to me that the situation hadn't changed.