Results 1 to 3 of 3

Thread: QObject and alarm clock

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QObject and alarm clock

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Shanghai, China
    Posts
    52
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QObject and alarm clock

    Hmmm...I would choose to implement it inside the Alarm class, seems more flexible
    1. Users don't have the manual, and if they did, they wouldn't read it.
    2. In fact, users can't read anything, and if they could, they wouldn't want to.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QObject and alarm clock

    Allow the alarm clock to be configured via its constructor or a setter method, and then the alarm clock looks after itself and fires the alarm signal when it's time.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.