To sum up, set screen saver in the embedded ARM Board:
There are two qwsscreensaver classes in QT.
The definition of this class is as follows:
Define pathQwindowsystem_qws.h
class Q_GUI_EXPORT QWSScreenSaver
|
088 |
virtual
~QWSScreenSaver(); |
089 |
virtual
void restore()=0; |
090 |
virtual
bool save( int
level)=0; |
Yes classMembers of the qwsserverprivate class, which are also related to the screen saver settings.
QTime screensavertime;
097 |
QTimer* screensavertimer;
|
098 |
int * screensaverintervals;
|
099 |
int
screensavereventblocklevel; |
100 |
bool
screensaverblockevents; |
101 |
bool
screensaverblockevent( int
index, int *screensaverinterval,
bool isDown );
|
102 |
QWSScreenSaver* saver;
|
void screenSave(
int
level);
When setting screen saver, the QT program should be run as the server. The virtual function virtual in qwsscreensaver
void
Restore () and virtual
bool
save(
int
Level) is used for overloading,
Set the processing in the screen saver status to reload in the subsequent functions. Set the processing to restore the screen saver to be executed in the previous virtual function. To save power consumption, I turn off the screen Backlight in the screen saver status, enable Backlight in the recovery status.
I use this method to perform a simple test to achieve dynamic Screen Saver time settings. Let's talk about the debugging process of this test.
Defines a screensaver class, inherited from qwsscreensaver
The class definition and implementation code is as follows:
# Ifndef screensaver_h
# Define screensaver_h
# Include <qwidget>
# Include <qwsserver>
Class screensaver: Public qwsscreensaver
{
Public:
Screensaver ();
Virtual void restore ();
Virtual bool save (INT level );
PRIVATE:
Int freq;
Int dutycycle;
Public slots:
Void screensaver_parameter_changed (INT );
};
# Endif // screensaver_h
The implementation file is as follows:
# Include "screensaver. H"
# Include <qdebug>
# Include <qtcore>
# Include <stdio. h>
# Include <stdlib. h>
# Include <unistd. h>
# Include <sys/IOCTL. h>
# Include <sys/STAT. h>
# Include <fcntl. h>
# Define ioctl_frequency 0
# Define ioctl_dutycycle 1
Static int FD;
Screensaver: Screensaver ()
: Qwsscreensaver ()
{
// Window = new qmainwindow ();
Qdebug () <"inlize ";
Qsettings * readini = new qsettings ("/home/config. ini", qsettings: iniformat, 0); // initialize the system to read the current backlight value and store it
Readini-> begingroup ("Backlight ");
Dutycycle = readini-> value ("backlight_duty"). toint ();
Qdebug ("dutycycle = % d", dutycycle );
Readini-> endgroup ();
Delete readini;
Freq = 6500;
}
Void screensaver: Restore ()
{
Qdebug ("Enter screen restore ");
// Open PWM
If (FD = open ("/dev/pwm9", o_rdwr) <0)
{
Printf ("open device gptimer8 error \ n ");
Exit (1); // close ();
}
Printf ("the frequecy is % d Hz \ n", freq );
Printf ("the duty cycle is % d percent \ n", dutycycle );
IOCTL (FD, ioctl_frequency, freq );
IOCTL (FD, ioctl_dutycycle, dutycycle );
: Close (FD );
}
Bool screensaver: Save (INT level)
{
// Close PWM anti-Logic
If (FD = open ("/dev/pwm9", o_rdwr) <0)
{
Printf ("open device gptimer8 error \ n ");
Exit (1); // close ();
}
Printf ("the frequecy is % d Hz \ n", freq );
Printf ("the duty cycle is 90 \ n ");
IOCTL (FD, ioctl_frequency, freq );
IOCTL (FD, ioctl_dutycycle, 100 );
: Close (FD );
Qdebug () <"window show ";
Return true;
}
Void screensaver: screensaver_parameter_changed (INT interval)
{
Qwsserver: setscreensaverinterval (interval * 1000 );
// Ignore the key/mouse event that turns on the screen
}
Some other settings are required for Screen Saver settings.
I create two other classes: input and mainwindow,
The mainwindow class is defined as follows:
Class mainwindos: Public qmainwindow
{
Q_object
Public:
Explicit mainwindos (qwidget * parent = 0 );
Qpushbutton * button;
Qpushbutton * screensaver_set;
Input * time_set;
Test * tes;
Screensaver * saver;
Qpushbutton * mousecalibration;
Calibration Cal;
Signals:
Public slots:
Void screeasaver_time_set ();
Void mouseclibration_set ();
};
Two member functions are defined, namely, saver and time_set, which are an object of ScreenSaver. time_set is an input window and the input time is used to change the hunger interval of screen saver,
Screensaver is set in the mainwindow constructor.
Saver = new screensaver;
Qwsserver: setscreensaver (qwsscreensaver *) saver );
Qwsserver: setscreensaverinterval (10000); // read the configuration file to get the Initial Value
Qwsserver: screensaveractivate (true );
// Int blocklevel = 1;
// Qwsserver: setscreensaverblocklevel (blocklevel );
I made a mistake, so this program has been called for a long time. I defined a connection in the mainwindows implementation function.
Connect (time_set, signal (saver_interval (INT), saver, slot (screensaver_parameter_changed (INT )));
The mainwindos. CPP: 46: Error: no matching function for call to 'mainwindos: connect (input * &, const char [21], screensaver * &, const char [36])'
I have never realized that as long as the class in QT can communicate in such a signal slot, I have created another class inherited from qwidget, which is used to receive the input data in the input window,
Connect (time_set, signal (saver_interval (INT), Tes, slot (screensaver_parameter_changed (INT )));
The result is normal. I checked the definition of qwsscreensaver, which has been posted above. When the signal slot method cannot be implemented and the time is updated immediately, we began to consider using the inter-process communication method, but it was obviously troublesome. Later, with the help of my colleagues, I directly modify the time interval in the input function of the input class, avoiding the trouble of passing time parameters.
Void input: button_click_slot ()
{
Qpushbutton * buttontem = qobject_cast <qpushbutton *> (sender ());
If (buttontem = UI-> Pushbutton)
{
Number ++;
}
Else
{
Number = buttontem-> text (). toint ();
}
Qdebug ("num = % d", number );
Qwsserver: setscreensaverinterval (Number * 1000 );
Emit saver_interval (number );
}
If you notice which statement can be used anywhere in the program, it will not be a headache for passing the time parameter.
I also saw some screen saver programs on the Internet:
I think it is feasible.
Reference Web site http://qtcn.org/bbs/read-htm-tid-38469-page-2.html
Http://blog.chinaunix.net/uid-27170912-id-3305962.html
Reload the function bool qapplication: qwseventfilter (qwsevent * event ).
The reload method is basically like the following:
Application. h
Copy code
- # Ifndef application_h
- # Define application_h
- # Include <qapplication>
- # Include <qdebug>
- Class Application: Public qapplication
- {
- Public:
- Application (Int & argc, char ** argv );
- Bool notify (qobject *, qevent *);
- Bool qwseventfilter (qwsevent * event );
- };
- # Endif // application_h
Application. cpp
Copy code
- # Include "application. H"
- Application: Application (Int & argc, char ** argv ):
- Qapplication (argc, argv)
- {
- }
- Bool application: Notify (qobject * OBJ, qevent * E)
- {
- // Do something
- Return qapplication: Y (OBJ, e );
- }
- Bool application: qwseventfilter (qwsevent * event)
- {
- // Do something
- Return qapplication: qwseventfilter (event );
- }
Main. cpp
Copy code
- # Include "application. H"
- # Include "mainwindow. H"
- Int main (INT argc, char * argv [])
- {
- Application A (argc, argv );
- Mainwindow W;
- W. Show ();
- Return a.exe C ();
- }
According to cutemmll's practices, the younger brother can indeed catch all mouse events
Bool application: Notify (qobject * OBJ, qevent * E)
{
If (e-> type () = qevent: mousebuttonpress)
{
// Do something
}
Return qapplication: Y (OBJ, e );
}
- Class Application: Public qapplication
- {
- Public:
- Application (Int & argc, char ** argv );
- Bool notify (qobject *, qevent *);
- Void setwindowinstance (mainwindow * WND );
- PRIVATE:
- Mainwindow * window; // save a pointer to your form
- };
- CPP
Copy code
- Application: Application (Int & argc, char ** argv)
- : Qapplication (argc, argv)
- , Window (0)
- {
- }
- Void application: setwindowinstance (mainwindow * WND)
- {
- Window = WND;
- }
- Bool application: Notify (qobject * OBJ, qevent * E)
- {
- If (e-> type () = qevent: mousemove)
- {
- If (window)
- {
- Window-> dosomething (); // call the corresponding function of your form
- }
- }
- Return qapplication: Y (OBJ, e );
- }
- Int main (INT argc, char * argv [])
- {
- Application app (argc, argv );
- Mainwindow W;
- W. Show ();
- App. setwindowinstance (& W );
- Return app.exe C ();
- } Another method is to rewrite the qapplication function to monitor the entire program. The source is http://qtcn.org/bbs/read-htm-tid-38469-page-2.html#. the project is too large to be easily uploaded. Header file: Class Application: Public qapplication
{Public:
Application (Int & argc, char ** argv );
Bool notify (qobject *, qevent *);
Void setwindowinstance (mainwindow * WND); Private:
Mainwindow * window; // save a pointer to your form}; CPP: Application (Int & argc, char ** argv)
: Qapplication (argc, argv)
, Window (0)
{
} Void application: setwindowinstance (mainwindow * WND)
{
Window = WND;
} Bool application: Notify (qobject * OBJ, qevent * E)
{
If (e-> type () = qevent: mousemove)
{
If (window)
{
Window-> dosomething (); // call the corresponding function of your form
}
}
Return qapplication: Y (OBJ, e );
} Main. cppint main (INT argc, char * argv [])
{
Application app (argc, argv );
Mainwindow W;
W. Show ();
App. setwindowinstance (& W );
Return app.exe C ();
} Another method is eventfilter: the function of bool qapplication: qwseventfilter (qwsevent * event) is not reloaded. # ifndef application_h
# Define application_h # include <qapplication>
# Include <qdebug> class application: Public qapplication
{
Public:
Application (Int & argc, char ** argv );
Bool notify (qobject *, qevent *);
Bool qwseventfilter (qwsevent * event) ;};# endif // application_h # include "application. H" Application: Application (Int & argc, char ** argv ):
Qapplication (argc, argv)
{
} Bool application: Notify (qobject * OBJ, qevent * E)
{
// Do something
Return qapplication: Y (OBJ, e );
} Bool application: qwseventfilter (qwsevent * event)
{
// Do something
Return qapplication: qwseventfilter (event );
} Main. PP: # include "application. H"
# Include "mainwindow. H" int main (INT argc, char * argv [])
{
Application A (argc, argv );
Mainwindow W;
W. Show (); Return a.exe C ();
}
- The Code on the internet is mainly implemented from the perspective of reload qapplication.