Results 1 to 4 of 4

Thread: QSound problem.

  1. #1
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default QSound problem.

    Hi,

    i have this command in my program,

    QSound::play ("sound/alert.wav");
    but the problem is,it doest play the whole wave, it just keep repeating the first few sec of the wave. and if i click my GUI, it will play the whole wave. what is wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSound problem.

    can we see the code where you use QSound::play(), seems it is inside a loop.

  3. #3
    Join Date
    Jul 2009
    Posts
    55
    Thanks
    3

    Default Re: QSound problem.

    Qt Code:
    1. if (nodeData.addr==0) //node 0
    2. {
    3. // Write node number
    4. //qsTemp.sprintf("Node: %d", nodeData.addr);
    5. qsTemp.sprintf("Access Point");
    6. //xpainter->setFont(addrFont);
    7. painter->setFont(timeFont);
    8. painter->drawText(-50,-15,100,20,Qt::AlignCenter , qsTemp,0);
    9. }
    10. else
    11. {
    12. // Write node number
    13. qsTemp.sprintf("End Device %d", nodeData.addr);
    14. //xpainter->setFont(addrFont);
    15. painter->setFont(timeFont);
    16. painter->drawText(-50,-22,100,20,Qt::AlignCenter , qsTemp,0);
    17.  
    18. //Write signal strength in ED node
    19. if (nodeData.strength > 21)
    20. {
    21. qsTemp.sprintf("Strong", nodeData.strength);
    22. painter->setFont(strengthFont);
    23. painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0);
    24. }
    25. else if (nodeData.strength > 15)
    26. {
    27. qsTemp.sprintf("Medium", nodeData.strength);
    28. painter->setFont(strengthFont);
    29. painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0);
    30. }
    31. else
    32. {
    33. qsTemp.sprintf("Weak", nodeData.strength);
    34. painter->setFont(strengthFont);
    35. painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0);
    36. }
    37. if (nodeData.temp > 80.6)
    38. {
    39. [COLOR="yellow"]QSound::play ("sound/alert.wav");[/COLOR]
    40. painter->setBrush (QColor(0x80, 0x80, 0x80,(nodeData.fadeNumber)));
    41. painter->drawEllipse(-45, -45, 100, 100);
    42. gradient.setCenter(3, 3);
    43. gradient.setFocalPoint(3, 3);
    44. QRadialGradient gradient(0, 0, 50, -20, -20);
    45. gradient.setColorAt(1, nodeAlertColor);
    46. gradient.setColorAt(.5, nodeAlertColorDark);
    47. gradient.setColorAt(0, nodeAlertColorDark);
    48. painter->setBrush(gradient);
    49. painter->setPen(QColor(0, 0, 0,(nodeData.fadeNumber)));
    50. painter->drawEllipse(-50, -50, 100, 100);
    51. if(celsius)
    52. {
    53. qsTemp.sprintf("ALERT!\n\ End Device %d\n\ %.1f°C\n\ ", nodeData.addr, ((nodeData.temp-32.0)/1.8));
    54. painter->setPen(QPen(Qt::black, 0));
    55. painter->setFont(timeFont);
    56. painter->drawText(-50,-50,100,100,Qt::AlignCenter , qsTemp,0);
    57. }
    58. else
    59. {
    60. qsTemp.sprintf("ALERT!\n\ End Device %d\n\ %.1f°F\n\ ", nodeData.addr, nodeData.temp);
    61. painter->setPen(QPen(Qt::black, 0));
    62. painter->setFont(timeFont);
    63. painter->drawText(-50,-50,100,100,Qt::AlignCenter , qsTemp,0);
    64. }
    65. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QSound problem.

    Ok, it's inside a paint function of a graphics item, but that get called several times for many reasons, so that is not the right place for play the sound. Better implement the sound play in the function where you set "nodeData.temp".

    Edit: or use a function where you also store the actual value of nodeData.temp and play only when the values are different

Similar Threads

  1. QSound problem
    By maverick_pol in forum Qt Programming
    Replies: 0
    Last Post: 3rd November 2008, 09:54
  2. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.