Search code examples
c++qtqt4audio

Qt: How to play sound witout blocking main thread?


I'm wondering is there a simple way in Qt to play sound without blocking the main thread ?

I know that normaly I should start a seperate thread to do this. But maybe there is a shortcut ? :)

Thanks for help.


Solution

  • http://doc.qt.nokia.com/latest/qsound.html

    Qt provides the most commonly required audio operation in GUI applications: asynchronously playing a sound file. This is most easily accomplished using the static play() function:

     QSound::play("mysounds/bells.wav");
    

    It seems like this is an asynchronous operation, so it shouldn't block your main thread.