+ Reply to Thread
Results 1 to 7 of 7

Thread: QSound problem playing different wav files

  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

  2. #2
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSound problem playing different wav files

    Did you try using the static member QSound::play() instead?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    31,030
    Thanks
    3
    Thanked 4,654 Times in 4,457 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QSound problem playing different wav files

    I'd say the problem might be in your linux system (or in NAS to be exact). I'd suggest using Phonon instead, it's much more reliable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: QSound problem playing different wav files

    Quote Originally Posted by wysota View Post
    I'd say the problem might be in your linux system (or in NAS to be exact). I'd suggest using Phonon instead, it's much more reliable.
    A little bit offtopic (sorry), but since you mentioned Phonon...do you know if it is possible to pass wav files to Phonon as resource files? I tried this once with QSound and failed miserably.

  5. #5
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSound problem playing different wav files

    Quote Originally Posted by victor.fernandez View Post
    Did you try using the static member QSound::play() instead?
    yes I did. same result

    Quote Originally Posted by wysota View Post
    I'd say the problem might be in your linux system (or in NAS to be exact). I'd suggest using Phonon instead, it's much more reliable.
    I wanted to stay away of phonon. I always have a problem with installation on windows etc but it looks like I have to use it :/

    Thanks all..
    Last edited by couker; 27th August 2009 at 15:34.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    31,030
    Thanks
    3
    Thanked 4,654 Times in 4,457 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QSound problem playing different wav files

    Quote Originally Posted by Kumosan View Post
    do you know if it is possible to pass wav files to Phonon as resource files?
    It should work with Phonon. As far as I remember you can pass any QIODevice to it, even a network socket.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2008
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSound problem playing different wav files

    Tried today after upgrade nas to 1.9.2 and everything is working..

+ Reply to Thread

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