Results 1 to 11 of 11

Thread: qt4 daemon

  1. #1
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qt4 daemon

    hello,
    i need an application running background which will continously check current time to some predefine time, and emit a signal whenever match.

    any help regarding this is a great favour.

  2. #2
    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: qt4 daemon

    Ok, but what exactly is the problem?
    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.


  3. #3
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qt4 daemon

    i made a dbus interface, run a method where in a forever loop i tried ..


    Qt Code:
    1. QDateTime aTime_=getTime(); //gives the same format as current
    2. while(1){
    3. QDateTime currTime=QDateTime::currentDateTime ();
    4. qDebug()<<currTime << aTime_;
    5. if(aTime_.date()==currTime.date()){
    6. qDebug()<<"date checked"
    7. emit signalTime();
    8. }
    9.  
    10. //this part never calls
    11. if(aTime_.time()==currTime.time()){
    12. qDebug()<<"time checked";
    13. emit signalTime();
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    aTime_.time()==currTime.time() ....this compare never calls, ???
    another question is Is that the right way to make a daemon, or there is any other alternatives..
    Last edited by wysota; 10th March 2009 at 23:04. Reason: missing [code] tags

  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: qt4 daemon

    If you run a while(1) loop, you are starving the event loop and it's not possible for your application to do anything. You should use QTimer instead. And your comparison never works because you'd have to trigger it in the exact time the other object points to (up to miliseconds).

    And have a look at this article:
    http://doc.trolltech.com/qq/qq27-responsive-guis.html
    Although it deals with GUI issues, it all applies to a non-gui application as well.
    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. The following user says thank you to wysota for this useful post:

    akon (10th March 2009)

  6. #5
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qt4 daemon

    thanks, much helpfull
    i will check it out.

  7. #6
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qt4 daemon

    hello wysota,
    know its a FAQ...
    may be I am doing some stupid mistake. it will be very helpful if u give a sample code snip, for this daemon running.

  8. #7
    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: qt4 daemon

    What exactly do you want? A snippet to use QTimer? Have you seen the docs of QTimer?
    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.


  9. #8
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qt4 daemon

    i got the problem....but still not getting the solution...


    QDateTime aTime_=getTime(); //gives the same format as current
    QDateTime currTime;
    currTime.setTimeSpec(Qt::UTC);
    currTime=QDateTime::currentDateTime();

    QTimer::singleShot(currTime.secsTo(aTime_)*1000, this, SLOT(slot_a_Mode()));

    qDebug()<<currTime<<aTime_<< "seconds to call..."<<currTime.secsTo(aTime_);

    ____________

    currTime.secsTo(aTime_); ----giving some unknown value, and I cant figure out why

  10. #9
    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: qt4 daemon

    Why are you compilating things so much?

    Qt Code:
    1. QTimer *timer = new QTimer(this);
    2. connect(timer, SIGNAL(timeout()), this, SLOT(checkTime()));
    3. timer->start(1000); // will fire every second
    4.  
    5. void ...::checkTime(){
    6. QDateTime ct = QDateTime::currentDateTime();
    7. if(qAbs(ct.toTime_t()-definedTime.toTime_t())<2){
    8. emit alarm();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    There is also another possibility, that you check the time before setting the timer and then set the timer to the exact number of miliseconds you need to reach the time you want.
    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.


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

    akon (11th March 2009)

  12. #10
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qt4 daemon

    one thing , how u came to know I m trying something with alarm,

  13. #11
    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: qt4 daemon

    You said you wanted to signal the approach of a predefined moment in time. That's what we call raising an alarm
    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.


Similar Threads

  1. DBus daemon not starting
    By Khal Drogo in forum Qt Programming
    Replies: 5
    Last Post: 7th August 2008, 16:12

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.