Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
Developer
Posts: 19
Registered: ‎11-13-2010
My Device: Not Specified
Accepted Solution

qtimer or sleep late?

I use the class of QTimer to handle the time out event.

It looks quite normal in the debug version, but in the release version sometimes the time out event is triggered too late(almost 10 seconds)!

 

And I change the method to use another thread to handle the time out event by using the system method: sleep or usleep.

But it still work in the debug version, and been triggered too late in the release version.

 

Could someone help me?

 

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: qtimer or sleep late?

are you using QTimer from QML or C++ ?

 

please tell something more about your usecase

what else is running while you're waiting for the timeout event

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 19
Registered: ‎11-13-2010
My Device: Not Specified

Re: qtimer or sleep late?

c++ and do nothing else, just start the qtimer then return

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: qtimer or sleep late?

is this just after starting the app or are you callin it later from QML ?

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 19
Registered: ‎11-13-2010
My Device: Not Specified

Re: qtimer or sleep late?

Once some other event (such as network connect) are triggered I start the qtimer in the c++  not in the qml

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: qtimer or sleep late?

Hi,

Could it be that you're performing some lengthy calculation in main loop which blocks the event loop?

I haven't encountered this problem when using QTimer, it always fired on time. It shouldn't be affected by debug or release mode. Most likely the problem is elsewhere. I can't really help without seeing the actual code.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: qtimer or sleep late?


Zmey wrote:
Hi,

Could it be that you're performing some lengthy calculation in main loop which blocks the event loop?

I haven't encountered this problem when using QTimer, it always fired on time. It shouldn't be affected by debug or release mode. Most likely the problem is elsewhere. I can't really help without seeing the actual code.

same for me

never had a problem with QTimer

worked perfect - even if APP is minimized

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 19
Registered: ‎11-13-2010
My Device: Not Specified

Re: qtimer or sleep late?

init 

 

success = connect(&_timer,
                               SIGNAL(timeout()),
                               this,
                               SLOT(handleTimeout()));
     Q_ASSERT(success);

 something happened:

void ApplicationUI::onUpdated()
{

     _timer.start(5* 1000);
}

 

handle

void ApplicationUI::handleTimeout()
{
showToast("handletimeout"); _timer.stop(); _timer.start(10 * 1000); }

 

I find the timeout sometimes happens later than 10 seconds in the  release version.

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: qtimer or sleep late?

hatmann1944, can you describe more about the conditions involved? Is the app fullscreen the entire time you're testing this, or do you minimize it sometimes (by swiping up to reveal the home screen) and maybe run other apps, then switch back to yours? Do you ever let the device go into standby while you're testing this?

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 1,178
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: qtimer or sleep late?

From QTimer documentation:

 

Accuracy and Timer Resolution

 

Timers will never time out earlier than the specified timeout value and they are not guaranteed to time out at the exact value specified. In many situations, they may time out late by a period of time that depends on the accuracy of the system timers.

 

The accuracy of timers depends on the underlying operating system and hardware. Most platforms support a resolution of 1 millisecond, though the accuracy of the timer will not equal this resolution in many real-world situations.

 

If Qt is unable to deliver the requested number of timer clicks, it will silently discard some.

 

That last line is possibly the most relevant. If your app or device is doing something that causes Qt to discard a lot of timer ticks it is possible you could see the signifcant innaccuracies you are encountering. Every tick dropped by Qt means the timeout will happen slightly later.

 

Is it possible the device you are testing on has something else running that is blocking long enough or often enough to drop a lot of ticks?


hatmann1944 wrote:

I use the class of QTimer to handle the time out event.

It looks quite normal in the debug version, but in the release version sometimes the time out event is triggered too late(almost 10 seconds)!

 

And I change the method to use another thread to handle the time out event by using the system method: sleep or usleep.

But it still work in the debug version, and been triggered too late in the release version.

 

Could someone help me?

 






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.