[Qt-interest] About the QSound,is thread safe?

Samuel Rødal sroedal at trolltech.com
Fri Nov 6 15:36:52 CET 2009


lvbing lvbing wrote:
> The platform: WinXp + Qt332
> In my application hase the function:
> void MProcess::resetSound
> {
>     if( sound != NULL)
>     {
>         sound->stop();
>         delete sound;
>         sound = NULL;
>     }
> }
> 
> void MProcess::PlaySound()
> {
>     resetSound();
>     sound = new QSound(fileName);
>     sound->setLoops(3000);
>     sound->play();
> }
> 
> The fuction MProcess::PlaySound() is registered to be called by some 
> callback function.
> In my callback function,it will call the function PlaySound,and 
> return.but sometime,
> when the function run to subfuction:MProcess::resetSound(),
> it delay at "sound->stop();"
> 
> I don't know why ?
> and is there something wrong with my function?
> 
> BTW:I need realized the function:
> In my callback function,I need select a wave file to paly,if the pre 
> wave file still play,stop it first,then play the
> new wave file.
> But the class QSound has not the way to change the wave file to play.
> or the static functionQSound::play(const QString& filename) can't set 
> the loops!
> and if I use QSound class to setLoops,and do I have to stop the QSound 
> first and delete it then,
> and create a new QSound object ?
> 
> Thanks

The QSound documentation doesn't mention thread-safety or reentrancy so 
it's probably safest to assume that it's not.

--
Samuel



More information about the Qt-interest-old mailing list