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:
void playFor();
public slots:
//void getPath();
void doSomething();
void clear();
void about();
void showTime();
void playAlarm();
void stopAlarm();
private:
};
#endif
#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
To copy to clipboard, switch view to plain text mode
here is the cpp:
{
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()));
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
}
void myQtApp::playAlarm(){
QSound::play("alarms/guitar.wav");
}
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");
}
To copy to clipboard, switch view to plain text mode
but when I put that on the main function, the wav file works:
{
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()));
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
}
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();
}
To copy to clipboard, switch view to plain text mode
Any idea why? Any help really epreciated! Thanks!
Bookmarks