-
Disable Screensaver
To disable the automatic screensaver lock-on and dim light:
-I have to include QtMobility on the .pro file:
CONFIG += mobility
MOBILITY += systeminfo
-Use QSystemScreenSaver->setScreenSaverInhibit():
[CODE] #include <QSystemScreenSaver>
QSystemScreenSaver *sss=new QSystemScreenSaver ( this );
sss->setScreenSaverInhibit();[/CODE]
My problem is I don't know if this code is right and where and how to include it. I was looking at the QtMobility examples but I cant figure out. Can anybody help me?
-
Re: Disable Screensaver
Hi,
the code looks right.
you can add that functionality to one of your classes like shown below
#include <QObject>
#include <QSystemScreenSaver>
class myClass : public QObject
{
Q_OBJECT
public:
explicit myClass(QObject *parent = 0): sss(0){}
void setScreenSaverInhibit(bool inhibit) ){
if (inhibit) {
if (sss) return;
sss = new QSystemScreenSaver (this);
sss->setScreenSaverInhibit();
} else {
delete sss;
sss = 0;
}
}
private:
QSystemScreenSaver *sss
};
-
Re: Disable Screensaver
Thanks for your answer. Im trying to figure out where do I have to include the code:
at the main.cpp? at qmlapplicationviewer.h?
Sorry but I have no clue.
-
Re: Disable Screensaver
BTW,
It seems it can be done from QML using QTMobility:
[URL="http://doc.qt.nokia.com/qtmobility-1.1/qml-screensaver.html"]http://doc.qt.nokia.com/qtmobility-1.1/qml-screensaver.html[/URL]
But I cant make it work either. :(
-
Re: Disable Screensaver
Ok, I got it.
To disable de screensaver using QtMobility:
-Enable QtMobility on the .pro file:
[CODE] CONFIG += mobility
MOBILITY += systeminfo[/CODE]
-Import QtMobility at the start of your main.qml file with this line:
[CODE] import QtMobility.systeminfo 1.1[/CODE]
-Add this element to your main.qml file:
[CODE] ScreenSaver { id: screenSaver
Component.onCompleted: {screenSaver.setScreenSaverDelayed(true) }
}[/CODE]
-
Re: Disable Screensaver
Hi Oscar,
I have used that code but it does not dim the lights? Did your use dim the lights as well?
Thanks,
MJ
-
Re: Disable Screensaver
[QUOTE=preeman;846294]Hi Oscar,
I have used that code but it does not dim the lights? Did your use dim the lights as well?
Thanks,
MJ[/QUOTE]
What this code does is disable the screensaver and *avoid* the lights dim.
-
Re: Disable Screensaver
ah ok, is there code that dims the lights as well? I have made a QML flip clock but I wanted an option for the user to leave it as a screen saver. If I use the code, screensaver is off, but the lights are still with big battery draw.
The project is at [url]http://bit.ly/j9p2A3[/url]