QSound example



  • I am trying to do an app and I want to use QSound.
    Unfortunately I can’t get it to work. I read the "documentation":http://doc.qt.nokia.com/latest/qsound.html but they don’t explain what’s the most important part: where do you store the audio file and how to declare it.
    Does anybody have a simple example that uses QSoud?

    A button that makes a sound when you press it or something like that.

    Thanks.



  • I would use a resource file and store my sounds in there and just use

    @
    void MainWindow::on_pushButton_clicked()
    {
    QSound sound(":/sounds/notification");
    sound.play();
    /*
    OR
    QSound::play(":/sounds/notification");
    */

    }
    @
    Where ":/" = the notification that u use a resource file.
    "/sounds/" = the prefix you made in your resource file.
    "notification" = the alias u gave the .wav file u use.
    Instead of using an alias u also can give the filename like "sound.wav", but i think its "better" to use an alias. That way u only have to change your resource file when u want to use an other sound for the notification.
    When u dont want to use a resourcefile just pass the whole "path to sound file" to the play function



  • From the doc:
    Note that QSound does not support resources. This might be fixed in a future Qt version.



  • That’s why I asked for a working example. I tried with the resource file, didn’t worked.
    I tried with the path to the file but here I get stuck. What is the relative path to file?

    How can I define the path so it works when I will compile for mobile ?



  • for Symbain just:
    @soundFiles.sources = sounds*.wav
    DEPLOYMENT += soundFiles@
    to Your project file
    and i code
    @QSound *sound = new QSound("some.wav",this);@



  • Is it Symbian or Windows?

    If it's linux it's not going to work.



  • In the end i will compile the app for Symbian. Right now i am just tring in the Qt SDK (on windows) but with no succes.



  • If your running it with QtSimulator, have You tried copping the sound files to the apps simulator folder? And I don't remember if simulator has sound output. QFile::exists might be helpful for debugging if the sound file gets found.



  • I got it to work, thanks guys.

    And i confirm, the sound doesn't work in the simulator, only on the symbian device. Good thing i had my C7 to test on. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.