I am making a alarm clock by creating a class Alarm:
#ifndef ALARMH_H
#define ALARMH_H
#include <QString>
#include <QTime>
#include <QDate>
{
Q_OBJECT
public:
};
#endif // ALARMH_H
#ifndef ALARMH_H
#define ALARMH_H
#include <QString>
#include <QTime>
#include <QDate>
class Alarm : public QObject
{
Q_OBJECT
public:
QString alarmName;
QTime alarmTime;
QDate alarmDate;
QString alarmSound;
QString alarmMessage;
QString alarmApp;
QString alarmAppArg;
};
#endif // ALARMH_H
To copy to clipboard, switch view to plain text mode
So I was wondering what is a better approach, to have a function checking on each new Alarm class instance created:
Alarm a1,a2,a3;
a1.setObjectName("a1");
a2.setObjectName("a2");
a3.setObjectName("a3");
QObjectList alarmList;
alarmList << a1 << a2 << a3;
void checkAlarm(QObjectList *list)
{
for(int i = 0;i <= list.count();i++){
check_if_its_time(list.at(i));
}
}
Alarm a1,a2,a3;
a1.setObjectName("a1");
a2.setObjectName("a2");
a3.setObjectName("a3");
QObjectList alarmList;
alarmList << a1 << a2 << a3;
void checkAlarm(QObjectList *list)
{
for(int i = 0;i <= list.count();i++){
check_if_its_time(list.at(i));
}
}
To copy to clipboard, switch view to plain text mode
Or if my class should check itself for the time and check if its time to ring the alarm:
#ifndef ALARMH_H
#define ALARMH_H
#include <QString>
#include <QTime>
#include <QDate>
{
Q_OBJECT
public:
void checkTime(){
// insert checking the time code
emit soundAlarm();
}
private:
signals:
soundAlarm();
};
#endif // ALARMH_H
// then in .cpp file I deal with the signal
#ifndef ALARMH_H
#define ALARMH_H
#include <QString>
#include <QTime>
#include <QDate>
class Alarm : public QObject
{
Q_OBJECT
public:
void checkTime(){
// insert checking the time code
emit soundAlarm();
}
private:
QString alarmName;
QTime alarmTime;
QDate alarmDate;
QString alarmSound;
QString alarmMessage;
QString alarmApp;
QString alarmAppArg;
signals:
soundAlarm();
};
#endif // ALARMH_H
// then in .cpp file I deal with the signal
To copy to clipboard, switch view to plain text mode
I hope you guys can understand what I mean.. Above code may not be compilable, may have let some things out as Im in a hurry and just trying to give an idea.
Bookmarks