QSound and the resource file
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:
Code:
QSound::play(":/Sounds/sound.wav");
QSound::play(":Sounds/sound.wav");
QSound::play("Sounds/sound.wav");
//I know the following works
So my question is what am I doing wrong in regards to playing sound from the current directory?
Thanks
Re: QSound and the resource file
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 could be helpful
Re: QSound and the resource file
Quote:
Originally Posted by
Lykurg
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 could be helpful
Thank you for the information, I followed your suggestions and it works like a charm.
Re: QSound and the resource file
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
Re: QSound and the resource file
Yes, please, someone please give a clear example of sucha basic thing anyone expects ..... :(
Re: QSound and the resource file
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.
Code:
//I know the following works
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).
Re: QSound and the resource file
Quote:
Originally Posted by
d_stranz
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.
Re: QSound and the resource file
Quote:
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.