In my latest game the players spend significant amount of time just watching the screen and trying to figure the puzzle out. The first few levels are obvious and most players will sole them in a few seconds, but as the difficulty of the puzzles increases the players stare at the screen longer and longer. At some point the screensaver would kick in and piss the player off (fortunately my ragtag QA/betatester team found this issue before launch).
Google search results are (as usual) helpful, but the most promising lead, the QSystemScreenSaver
class is not a solution. There are three problems with it:
- The API of the class itself is terrible.
- The API of the related QML element is even worse.
- Last, but not least, it doesn’t work (at least not in the Qt Mobility version shipped with the Qt SDK).
(BTW: these three points sums up pretty much every experience with Qt Mobility package I had. Qt devs should either kill this festering boil with fire or fix it and rename it, because I learned to dread everything remotely related to Qt Mobility, and I suspect I’m not the only one).
Anyways, let’s get back to the core of the problem, i.e. “how to block the screensaver”. Qt Mobility failed, but the task doesn’t seems like a rocket science to me. Slightly different Google search suggested using native Symbian’s User::ResetInactivityTime()
method. Few minutes and one QTimer
later, everything worked:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
The important thing in the code above is watching the ApplicationActivate
and ApplicationDeactivate
events – after all, when your app is in background, you shouldn’t affect the phone behavior. I’m not sure if the app would fail the Nokia’s QA process without this feature, but it seemed prudent to write the code this way.
If you want to use this object in your QML UI just register it with qmlRegisterType
and add the registered import and QML element to your root element.