PDA

View Full Version : About the QSound,is thread safe?



cspp
6th November 2009, 14:26
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