I am making a alarm clock by creating a class Alarm:
Qt Code:
  1. #ifndef ALARMH_H
  2. #define ALARMH_H
  3. #include <QString>
  4. #include <QTime>
  5. #include <QDate>
  6.  
  7. class Alarm : public QObject
  8. {
  9. Q_OBJECT
  10.  
  11. public:
  12. QString alarmName;
  13. QTime alarmTime;
  14. QDate alarmDate;
  15. QString alarmSound;
  16. QString alarmMessage;
  17. QString alarmApp;
  18. QString alarmAppArg;
  19. };
  20.  
  21. #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:
Qt Code:
  1. Alarm a1,a2,a3;
  2. a1.setObjectName("a1");
  3. a2.setObjectName("a2");
  4. a3.setObjectName("a3");
  5. QObjectList alarmList;
  6. alarmList << a1 << a2 << a3;
  7.  
  8. void checkAlarm(QObjectList *list)
  9. {
  10. for(int i = 0;i <= list.count();i++){
  11. check_if_its_time(list.at(i));
  12. }
  13. }
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:
Qt Code:
  1. #ifndef ALARMH_H
  2. #define ALARMH_H
  3. #include <QString>
  4. #include <QTime>
  5. #include <QDate>
  6.  
  7. class Alarm : public QObject
  8. {
  9. Q_OBJECT
  10.  
  11. public:
  12. void checkTime(){
  13. // insert checking the time code
  14. emit soundAlarm();
  15. }
  16. private:
  17. QString alarmName;
  18. QTime alarmTime;
  19. QDate alarmDate;
  20. QString alarmSound;
  21. QString alarmMessage;
  22. QString alarmApp;
  23. QString alarmAppArg;
  24.  
  25. signals:
  26. soundAlarm();
  27. };
  28.  
  29. #endif // ALARMH_H
  30.  
  31. // 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.