Qt c++ play sound on key press - stops working after a few seconds
I'm making an apllication which needs to play .wav file when user type something inside QTextEdit. I made some code but after minute or less the sound stops, so I made silly workarround. After 30 clicks I invoke sound->stop(); and then the loop start again, that works, but it's not good, can you give better solution. Here is my code:
Code:
int count = 0;
bool MainWindow::eventFilter(QObject *o, QEvent *e){
if(e->type() == QEvent::KeyPress)
{
tipka->play();
tipka->seek(0);
count++;
if(count == 30){
tipka->pause();
count = 0;
}
}
return false;
}
(tipka is Phonon::MediaObject)
Re: Qt c++ play sound on key press - stops working after a few seconds
what do you want to do?
is it short beep that occurs when the user presses a key, or a longer one?
you cant seek when the sound is in the stopped state, try omitting the seek(0) or use stop() instead.