CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012
    Posts
    3

    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)

  2. #2
    Join Date
    Jun 2012
    Posts
    58

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured