Results 1 to 3 of 3

Thread: QSound Issue

  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QSound Issue

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QSound Issue

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    loveablepocky (16th February 2011)

  4. #3
    Join Date
    Feb 2011
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSound Issue

    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
    Qt Code:
    1. case Qt::Key_S: sButton->setDown(true); keyS->play(); break;
    To copy to clipboard, switch view to plain text mode 

    This is to stop the sound
    Qt Code:
    1. case Qt::Key_S: sButton->setDown(false); keyS->stop(); break;
    To copy to clipboard, switch view to plain text mode 
    Last edited by loveablepocky; 16th February 2011 at 03:31.

Similar Threads

  1. Path to my QSound
    By ardisaz in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 13th November 2010, 07:22
  2. QSound problem?
    By anafor2004 in forum Qt Programming
    Replies: 3
    Last Post: 19th November 2008, 04:09
  3. QSound problem
    By maverick_pol in forum Qt Programming
    Replies: 0
    Last Post: 3rd November 2008, 09:54
  4. QSound.
    By csvivek in forum Qt Programming
    Replies: 2
    Last Post: 23rd June 2008, 22:02
  5. Is QSound all there is?
    By ad5xj in forum Newbie
    Replies: 4
    Last Post: 1st September 2007, 01:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.