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>
{
Q_OBJECT
public slots:
void playError();
void playOk();
public:
foo();
};
#endif
#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
To copy to clipboard, switch view to plain text mode
#include <QApplication>
#include "sound.h"
foo::foo()
{
connect(button, SIGNAL(clicked()), this, SLOT(playOk()));
connect(button2, SIGNAL(clicked()), this, SLOT(playError()));
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[])
{
foo* bar = new foo();
bar->show();
return app.exec();
}
#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();
}
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
Bookmarks