Results 1 to 7 of 7

Thread: QSound problem playing different wav files

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSound problem playing different wav files

    Hello,
    I need to play a wav file when pressing a button. Its quite simple with QSound, but I have a problem with playing more then one wav file on Linux.

    Example:
    Qt Code:
    1. #ifndef SOUND_H
    2. #define SOUND_H
    3.  
    4. #include <QPushButton>
    5. #include <QHBoxLayout>
    6. #include <QWidget>
    7. #include <QSound>
    8.  
    9. class foo : public QWidget
    10. {
    11. Q_OBJECT
    12.  
    13. public slots:
    14. void playError();
    15. void playOk();
    16.  
    17. public:
    18. QSound* m_error;
    19. QSound* m_ok;
    20. foo();
    21. };
    22. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QApplication>
    2. #include "sound.h"
    3.  
    4. foo::foo()
    5. {
    6. QPushButton* button = new QPushButton("ok");
    7. connect(button, SIGNAL(clicked()), this, SLOT(playOk()));
    8. QPushButton* button2 = new QPushButton("err");
    9. connect(button2, SIGNAL(clicked()), this, SLOT(playError()));
    10. QHBoxLayout* layout = new QHBoxLayout(this);
    11. layout->addWidget(button);
    12. layout->addWidget(button2);
    13. m_error = new QSound("err.wav");
    14. m_ok = new QSound("done.wav");
    15. }
    16. void foo::playError() { m_error->play(); }
    17. void foo::playOk() { m_ok->play(); }
    18.  
    19. int main(int argc, char *argv[])
    20. {
    21. QApplication app(argc, argv);
    22. foo* bar = new foo();
    23. bar->show();
    24. return app.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 

    When I press ok button (even more then one), I can play wav file without a problem. But when I press one button (sound play) and then press second button it doesn't play the file. After it it doesn't play the file even on first button. It doesn't work for me on linux (gentoo, 2.6.29, nas installed). I haven't this problem on windows machine..What I am missing ?
    Thanks for help
    Attached Files Attached Files

Similar Threads

  1. Playing Media files in Qt 4
    By sar_van81 in forum Qt Programming
    Replies: 2
    Last Post: 18th December 2007, 05:53
  2. problem with include files
    By JR in forum General Discussion
    Replies: 2
    Last Post: 22nd December 2006, 20:44
  3. Problem converting .ui files from Qt3 to 4
    By Amanda in forum Qt Programming
    Replies: 6
    Last Post: 28th October 2006, 04:34
  4. Replies: 1
    Last Post: 7th July 2006, 10:14
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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.