PDA

View Full Version : QSound being partial



been_1990
12th March 2009, 20:53
I use a simple QSound::play . I created a playAlarm() function to start it, but all I get when I click the button is the annoying Vista sound "tã"!

here is the header:


#ifndef MYQTAPP_H
#define MYQTAPP_H

#include "ui_myqtapp.h"
#include <QString>
#include <QSound>

class myQtApp : public QWidget, private Ui::myQtAppDLG
{
Q_OBJECT

public:
myQtApp(QWidget *parent = 0);
void playFor();

public slots:
//void getPath();
void doSomething();
void clear();
void about();
void showTime();
void playAlarm();
void stopAlarm();

private:
QTime currTime;
QString currTimeText;
};


#endif

here is the cpp:


myQtApp::myQtApp(QWidget *parent)
{
setupUi(this);
connect( pushButton_do, SIGNAL( clicked() ), this, SLOT( doSomething() ) );
connect( pushButton_clear, SIGNAL( clicked() ), this, SLOT( clear() ) );
connect( pushButton_about, SIGNAL( clicked() ), this, SLOT( about() ) );
connect( startButton, SIGNAL( clicked() ), this, SLOT( playAlarm() ));
connect( stopButton, SIGNAL( clicked() ), this, SLOT( stopAlarm()));

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
}


void myQtApp::playAlarm(){
QSound::play("alarms/guitar.wav");
}

but when I put that on the main function, the wav file works:


myQtApp::myQtApp(QWidget *parent)
{
setupUi(this);
// QSound::play("alarms/guitar.wav");
connect( pushButton_do, SIGNAL( clicked() ), this, SLOT( doSomething() ) );
connect( pushButton_clear, SIGNAL( clicked() ), this, SLOT( clear() ) );
connect( pushButton_about, SIGNAL( clicked() ), this, SLOT( about() ) );
connect( startButton, SIGNAL( clicked() ), this, SLOT( playAlarm() ));
connect( stopButton, SIGNAL( clicked() ), this, SLOT( stopAlarm()));

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
}

Any idea why? Any help really epreciated! Thanks!

JimDaniel
13th March 2009, 00:10
It looks right to me. What happens when you use an absolute path to the wav file?

been_1990
13th March 2009, 16:30
It looks normal, no compiler errors, but no sound comes when I call the function. Only that "tã" sound .

JimDaniel
13th March 2009, 16:36
Does it not work even if you put the sound on your root drive and call:


QSound::play("c:/guitar.wav");


I'm asking because it seems like it might not be finding the file from the relative path.

been_1990
13th March 2009, 18:33
Oooooops..... My bad! Just spotted the problem... I put a absolute path to it and now its all working. I had misspelled the audio file. :p :o