PDA

View Full Version : QSound problem playing different wav files



couker
26th August 2009, 23:05
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:


#ifndef SOUND_H
#define SOUND_H

#include <QPushButton>
#include <QHBoxLayout>
#include <QWidget>
#include <QSound>

class foo : public QWidget
{
Q_OBJECT

public slots:
void playError();
void playOk();

public:
QSound* m_error;
QSound* m_ok;
foo();
};
#endif





#include <QApplication>
#include "sound.h"

foo::foo()
{
QPushButton* button = new QPushButton("ok");
connect(button, SIGNAL(clicked()), this, SLOT(playOk()));
QPushButton* button2 = new QPushButton("err");
connect(button2, SIGNAL(clicked()), this, SLOT(playError()));
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(button);
layout->addWidget(button2);
m_error = new QSound("err.wav");
m_ok = new QSound("done.wav");
}
void foo::playError() { m_error->play(); }
void foo::playOk() { m_ok->play(); }

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
foo* bar = new foo();
bar->show();
return app.exec();
}


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

victor.fernandez
27th August 2009, 09:20
Did you try using the static member QSound::play() instead?

wysota
27th August 2009, 10:28
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.

Kumosan
27th August 2009, 10:36
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.

couker
27th August 2009, 11:45
Did you try using the static member QSound::play() instead?

yes I did. same result :(


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..

wysota
27th August 2009, 12:36
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.

couker
16th September 2009, 20:38
Tried today after upgrade nas to 1.9.2 and everything is working..