Results 1 to 6 of 6

Thread: How to make scheduler in QT4.4.2?

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Question How to make scheduler in QT4.4.2?

    Hi all

    Working on Qt4.4.2 on my Intel-mac machine, I want to develop a Time Scheduler in Qt, So that my application runs automatically acc. to the scheduled time.
    Always Believe in Urself
    Merry

  2. #2
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make scheduler in QT4.4.2?

    Use QDateTime class. Make a list with tasks and dates and compare the dates periodically with QDateTime::currentDateTime().
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  3. #3
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make scheduler in QT4.4.2?

    I've done this in an application of mine, using QTimer polling every 5 - 10 seconds or so.
    The only problem with the technique I find though is that if the tick happens 1 second before the start time, then it starts 4 seconds late.
    Apart from actually shortening the interval, is there another way to get the schedule launched bang on time?

    I understand that win32 has events you can hook into an event and wait using WaitForSingleObject which fires as soon as the clock ticks to the start time you're interested in. I'm not sure how crontab does it under *nix, but I've never seen a process start late before.
    I'm feeling that it's going to be platform specific code here to get a reliable scheduler going. Am I wrong?


    Steve

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make scheduler in QT4.4.2?

    Quote Originally Posted by stevey View Post
    Apart from actually shortening the interval, is there another way to get the schedule launched bang on time?
    You don't have to periodically check the queue. You know when the first event in the queue will occur so you can set the timer to exactly that moment in time. If someone happens to add another event which is earlier than the one that used to be the first one, simply adjust the timer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2006
    Posts
    140
    Thanks
    8
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to make scheduler in QT4.4.2?

    Sorry Wysota, which "queue" are you talking about here?
    Are you relating to "Single Shot" or something else?
    Any chance of a code sample to fire at 10:00am?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make scheduler in QT4.4.2?

    Qt Code:
    1. QTimer timer;
    2. timer.setSingleShot(true);
    3. connect(&timer, SIGNAL(timeout()), ..., SLOT(processQueue()));
    4. QList<Task> tasks;
    5. tasks.insert(...);
    6. QDateTime now = QDateTime::currentDateTime();
    7. QDateTime expected = tasks.top().dateTime(); // i.e. 09-08-31 10:00
    8. uint secs = expected.toTime_t() - now.toTime_t();
    9. timer.stop();
    10. timer.start(secs*1000);
    11. //...
    12.  
    13. void ...::processQueue(){
    14. Task t = queue.first();
    15. queue.removeFirst();
    16. t.perform();
    17. if(queue.isEmpty()) return;
    18. QDateTime now = QDateTime::currentDateTime();
    19. QDateTime expected = tasks.top().dateTime();
    20. uint secs = expected.toTime_t() - now.toTime_t();
    21. timer.stop();
    22. timer.start(secs*1000);
    23. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    stevey (31st August 2009)

Similar Threads

  1. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  2. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

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.