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?
Printable View
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?
can we see the code where you use QSound::play(), seems it is inside a loop.
Code:
if (nodeData.addr==0) //node 0 { // Write node number //qsTemp.sprintf("Node: %d", nodeData.addr); qsTemp.sprintf("Access Point"); //xpainter->setFont(addrFont); painter->setFont(timeFont); painter->drawText(-50,-15,100,20,Qt::AlignCenter , qsTemp,0); } else { // Write node number qsTemp.sprintf("End Device %d", nodeData.addr); //xpainter->setFont(addrFont); painter->setFont(timeFont); painter->drawText(-50,-22,100,20,Qt::AlignCenter , qsTemp,0); //Write signal strength in ED node if (nodeData.strength > 21) { qsTemp.sprintf("Strong", nodeData.strength); painter->setFont(strengthFont); painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0); } else if (nodeData.strength > 15) { qsTemp.sprintf("Medium", nodeData.strength); painter->setFont(strengthFont); painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0); } else { qsTemp.sprintf("Weak", nodeData.strength); painter->setFont(strengthFont); painter->drawText(-50,-8,100,20,Qt::AlignCenter , qsTemp,0); } if (nodeData.temp > 80.6) { painter->drawEllipse(-45, -45, 100, 100); gradient.setCenter(3, 3); gradient.setFocalPoint(3, 3); gradient.setColorAt(1, nodeAlertColor); gradient.setColorAt(.5, nodeAlertColorDark); gradient.setColorAt(0, nodeAlertColorDark); painter->setBrush(gradient); painter->drawEllipse(-50, -50, 100, 100); if(celsius) { qsTemp.sprintf("ALERT!\n\ End Device %d\n\ %.1f°C\n\ ", nodeData.addr, ((nodeData.temp-32.0)/1.8)); painter->setFont(timeFont); painter->drawText(-50,-50,100,100,Qt::AlignCenter , qsTemp,0); } else { qsTemp.sprintf("ALERT!\n\ End Device %d\n\ %.1f°F\n\ ", nodeData.addr, nodeData.temp); painter->setFont(timeFont); painter->drawText(-50,-50,100,100,Qt::AlignCenter , qsTemp,0); } }
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