PDA

View Full Version : QSound Issue



loveablepocky
15th February 2011, 22:42
Hi,

I'm new to Qt and lately I've been working on a project that has is using setDown() to hold down a button when the user holds down a key on the keyboard. I linked a sound to it as well and it seems to be playing when the user holds down the key and stops when the user no longer holds the key down. I'm using QSound since I'm unable to configure Phonon onto my windows computer.

The problem is, when the sound is played for longer than a second or so, it starts looping itself, making it sound like a glitch. It's similar to if you hold down the letter "a", then the first one appears, but a whole bunch of "a" appears after it. Is there a way to fix this so that when the key is held down, the sound is only played once so it doesn't sound like a glitch sound?

Thank you.

high_flyer
15th February 2011, 22:55
Is there a way to fix this so that when the key is held down, the sound is only played once so it doesn't sound like a glitch sound?
if you show your code probably yes.
My guess is that you are playing the sound as part of the press event.
You could add a boolean flag - which you flag when the sound has been played, and you play the sound only when the flag is not set.
You then unset the flag in the key release event.

loveablepocky
15th February 2011, 23:27
Okay that makes sense! Thanks! :)
I don't have the actual code in front of me at the moment, but basically my code is something like this:

This is to play the sound, holding down the "s" key

case Qt::Key_S: sButton->setDown(true); keyS->play(); break;

This is to stop the sound

case Qt::Key_S: sButton->setDown(false); keyS->stop(); break;