QSound::stop() und QTimer::stop() [solved - doku]
Verfasst: 24. Januar 2011 13:16
Hi
Ich hab ein kleines Problem mit nem sehr einfachen "Wecker" und zwar Crasht mir "alert->stop()" und "alertTimer->stop()" das App und ich komm einfach nicht drauf wieso.
Da ich nicht so bewandert oder gut in C++ bin wollte ich mal fragen ob mir jemand sagen kann wieso
Ich hab ein kleines Problem mit nem sehr einfachen "Wecker" und zwar Crasht mir "alert->stop()" und "alertTimer->stop()" das App und ich komm einfach nicht drauf wieso.
Da ich nicht so bewandert oder gut in C++ bin wollte ich mal fragen ob mir jemand sagen kann wieso
Code: Alles auswählen
#include <QtGui>
#include "clock.h"
#include "ui_clock.h"
#include <QDebug>
Clock::Clock() {
ui.setupUi(this);
// Orginal Palette
QPalette palette = ui.clockTime->palette();
// Timer Objects
QTimer* clockTimer = new QTimer(this);
QTimer* alertTimer = new QTimer(this);
alertTimer->setInterval(1000);
// Singals and Slots
connect(clockTimer, SIGNAL(timeout()), this, SLOT(showTime()));
connect(alertTimer, SIGNAL(timeout()), this, SLOT(checkAlert()));
connect(ui.buttonBox, SIGNAL(accepted()), alertTimer, SLOT(start()));
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(stopAlert()));
clockTimer->start(1000);
showTime();
}
void Clock::showTime() {
QTime time = QTime::currentTime();
QString text = time.toString("hh:mm");
ui.clockTime->display(text);
}
void Clock::checkAlert() {
qDebug() << "Armed!";
QTime time = QTime::currentTime();
QString text = time.toString("hh:mm:ss");
QPalette alertPalette = ui.clockTime->palette();
alertPalette.setColor(QPalette::Normal, QPalette::Foreground, Qt::red);
if (checkDay() && text == ui.alertTime->text()) {
qDebug() << "ALERT";
ui.clockTime->setPalette(alertPalette);
playSound();
}
}
void Clock::stopAlert() {
alert->stop();
alertTimer->stop();
ui.clockTime->setPalette(palette);
}
void Clock::playSound() {
//qDebug() << QSound::isAvailable();
qDebug() << "playSound";
QSound* alert = new QSound("bell.wav",this);
//alert->setLoops(360);
alert->play();
}
bool Clock::checkDay() {
QDate day;
//qDebug() << day.shortDayName(day.dayOfWeek());
switch (day.dayOfWeek()) {
case 1:
if (ui.Mon->isChecked()) {
return true;
}
case 2:
if (ui.Tue->isChecked()) {
return true;
}
case 3:
if (ui.Wed->isChecked()) {
return true;
}
case 4:
if (ui.Thur->isChecked()) {
return true;
}
case 5:
if (ui.Fri->isChecked()) {
return true;
}
case 6:
if (ui.Sat->isChecked()) {
return true;
}
case 7:
if (ui.Sun->isChecked()) {
return true;
}
default: return false;
}
}
Code: Alles auswählen
#ifndef CLOCK_H
#define CLOCK_H
#include <ui_clock.h>
#include <QSound>
class Clock: public QDialog {
Q_OBJECT
public:
Clock();
~Clock() {};
private:
Ui::Dialog ui;
QTimer* alertTimer;
QPalette palette;
QSound* alert;
private slots:
void showTime();
bool checkDay();
void checkAlert();
void playSound();
void stopAlert();
};
#endif // CLOCK_H