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.
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.
i made a dbus interface, run a method where in a forever loop i tried ..
Qt Code:
while(1){ qDebug()<<currTime << aTime_; if(aTime_.date()==currTime.date()){ qDebug()<<"date checked" emit signalTime(); } //this part never calls if(aTime_.time()==currTime.time()){ qDebug()<<"time checked"; emit signalTime(); } }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 22:04. Reason: missing [code] tags
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.
akon (10th March 2009)
thanks, much helpfull
i will check it out.
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.
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
Why are you compilating things so much?
Qt Code:
connect(timer, SIGNAL(timeout()), this, SLOT(checkTime())); timer->start(1000); // will fire every second void ...::checkTime(){ if(qAbs(ct.toTime_t()-definedTime.toTime_t())<2){ emit alarm(); } }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.
akon (11th March 2009)
one thing , how u came to know I m trying something with alarm,
You said you wanted to signal the approach of a predefined moment in time. That's what we call raising an alarm
Bookmarks