+ Reply to Thread
Results 1 to 8 of 8

Thread: QSound and the resource file

  1. #1

    Default 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:
    Qt Code:
    1. QSound::play(":/Sounds/sound.wav");
    2.  
    3. QSound::play(":Sounds/sound.wav");
    4.  
    5. QSound::play("Sounds/sound.wav");
    6.  
    7.  
    8. //I know the following works
    9. QSound::play("C:/sound.wav");
    To copy to clipboard, switch view to plain text mode 


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

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,002 Times in 912 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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

  3. The following user says thank you to Lykurg for this useful post:

    dhice (19th March 2009)

  4. #3

    Default Re: QSound and the resource file

    Quote Originally Posted by Lykurg View Post
    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.

  5. #4
    Join Date
    Feb 2010
    Location
    Los Angeles
    Posts
    61
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  6. #5
    Join Date
    Feb 2016
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSound and the resource file

    Yes, please, someone please give a clear example of sucha basic thing anyone expects .....

  7. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,117
    Thanks
    194
    Thanked 491 Times in 481 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default 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.

    Qt Code:
    1. //I know the following works
    2. QSound::play("C:/sound.wav");
    To copy to clipboard, switch view to plain text mode 

    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).
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #7
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,306
    Thanked 239 Times in 235 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSound and the resource file

    Quote Originally Posted by d_stranz View Post
    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.

  9. The following user says thank you to Lesiok for this useful post:

    d_stranz (19th May 2017)

  10. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,117
    Thanks
    194
    Thanked 491 Times in 481 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QSound and the resource file

    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.
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts