#include <QtGui>#include "widget.h"void Timer::updateTime(){ QTime time = QTime::currentTime(); QString text = time.toString("hh:mm"); lcd->display(text);}void Timer::playAlarm(){ QMessageBox::information(this, "Alarm", "Good Morning"); // добавить воспроизведение мелодии}void Timer::getAlarmTime(){ bool OK; int hours = QInputDialog::getInt(this, "Input Hours", "Hour: ", 12, 0, 23, 1, &OK); int minutes = QInputDialog::getInt(this, "Input Minutes", "Minutes: ", 30, 0, 59, 1, &OK);}Timer::Timer(){ timer = new QTimer; set = new QPushButton("Set"); quit = new QPushButton("Quit"); set->setMinimumSize(160, 20); quit->setMinimumSize(160, 20); lcd = new QLCDNumber; lcd->setSegmentStyle(QLCDNumber::Flat); lcd->setFrameStyle(2); lcd->setMinimumSize(160, 50); layout = new QVBoxLayout; layout->setMargin(10); layout->setSpacing(10); layout->addWidget(lcd); layout->addWidget(set); layout->addWidget(quit); this->setLayout(layout); QObject::connect(timer, SIGNAL(timeout()), this, SLOT(updateTime())); timer->start(500); updateTime(); QObject::connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); QObject::connect(set, SIGNAL(clicked()), this, SLOT(getAlarmTime()));}
void Timer::playAlarm(){ QMessageBox::information(this, "Alarm", "Good Morning"); // добавить воспроизведение мелодии}void Timer::getAlarmTime(){ bool OK; int alarm_hour = QInputDialog::getInt(this, "Input Hours", "Hour: ", 12, 0, 23, 1, &OK); int alarm_minute = QInputDialog::getInt(this, "Input Minutes", "Minutes: ", 30, 0, 59, 1, &OK); QTime qtime_time = QTime::currentTime(); QString qstring_hour = qtime_time.toString("hh"); QString qstring_minute = qtime_time.toString("mm"); int current_hour = qstring_hour.toInt(); int current_minute = qstring_hour.toInt(); int delay_hour; if (current_hour > alarm_hour) { delay_hour = ((24 - current_hour) + alarm_hour); } else if ((current_hour == alarm_hour) && (current_minute < alarm_minute)) { delay_hour = 0; } else if ((current_hour == alarm_hour) && (current_minute > alarm_minute)) { delay_hour = 23; } else delay_hour = (alarm_hour - current_hour); int delay_minute; if (current_minute > alarm_minute) { delay_minute = ((60 - current_minute) + alarm_minute); } else { delay_minute = (alarm_minute - current_minute); } int delay = (((alarm_hour * 3600) + (alarm_minute * 60)) * 1000); QTimer::singleShot(delay, this, SLOT(playAlarm()));}
QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(update())); timer->start(1000);
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(updateTime())); timer->start(500);
... QObject::connect(alarm_timer, SIGNAL(timeout()), this, SLOT(playAlarm())); alarm_timer->start(delay);
void Timer::playAlarm(){ //QMessageBox::information(this, "Alarm", "Good Morning"); // добавить воспроизведение мелодии}
class Timer : public QWidget{ Q_OBJECT...}
C++ (Qt)Timer(QWidget *parent = 0); Timer::Timer(QWidget *parent) : QWidget(parent){ ....}
C++ (Qt)class Timer : public QWidget{ Q_OBJECT public: Timer(QWidget *parent = 0);...}
C++ (Qt)void Timer::getAlarmTime(){ ... QTimer::singleShot(delay, this, SLOT(playAlarm()));}
C++ (Qt)Timer::Timer(QWidget *parent) : QWidget(parent){ ... QObject::connect(set, SIGNAL(clicked()), this, SLOT(getAlarmTime()));}