// Cel. h // Header file of subroutine 1 # Ifndef cel_h # Define cel_h# Include <qwidget> Class qslider; Class qhboxlayout; Class cel: Public qwidget { Q_object Public: Cel (); ~ Cel (){}; Private slots:
Void handlemsg (const qstring & message, const qbytearray & data );
Void sendmsg (INT celnum ); // Slot PRIVATE: Void fahtocel (INT fahnum ); Void createscreen (); Void createcel (); Void listenchannel (); Qslider * slider; Qhboxlayout * cellayout; }; // Cel. cpp # Endif // cel_h # Include <qpushbutton> # Include <qslider> # Include <qlabel> # Include <qlcdnumber> # Include <qvboxlayout> # Include <qhboxlayout> # Include <qapplication> # Include <qcopchannel> # Include <qdatastream> # Include <qbytearray> # Include "cel. H" Cel: cel (): qwidget () { Createscreen (); Listenchannel (); } Void cel: createscreen () { Qpushbutton * quitbtn = new qpushbutton ("quit "); Createcel (); Qvboxlayout * mainlayout = new qvboxlayout; Mainlayout-> addwidget (quitbtn ); Mainlayout-> addlayout (cellayout ); Setlayout (mainlayout ); Slider-> setfocus (); Connect (quitbtn, signal (clicked (), qapp, slot (quit ())); Setwindowtitle ("Celsius "); } Void cel: createcel () { Slider = new qslider (QT: vertical ); Slider-> setrange (0,100 ); Slider-> setvalue (0 ); Slider-> settickposition (qslider: ticksleft ); Qlabel * cellabel = new qlabel ("0 "); Cellayout = new qhboxlayout; Cellayout-> addwidget (cellabel, 0, QT: alignright ); Cellayout-> addwidget (slider, 0, QT: alignleft ); Cellayout-> setspacing (10 ); Connect (slider, signal (valuechanged (INT), cellabel, slot (setnum (INT ))); Connect (slider, signal (valuechanged (INT), this, slot (sendmsg (INT ))); } Void cel: fahtocel (INT fahnum) { Int celnum = (fahnum-32) * 5/9; Slider-> setvalue (celnum ); } Void cel: listenchannel () { Qcopchannel * channel = new qcopchannel ("/system/temperature", this); // register a channel Connect (Channel, signal (received (const qstring &, const qbytearray &)),
This, slot (handlemsg (const qstring &, const qbytearray &))); } Void cel: handlemsg (const qstring & message, const qbytearray & Data) // process received information {
Qdatastream in (data );
If (Message = "convertfahtocel (INT )")
{
Int fahnum;
In> fahnum;
Fahtocel (fahnum );
} } Void cel: sendmsg (INT celnum) // Send information {
Qbytearray data;
Qdatastream out (& Data, qiodevice: writeonly );
Out <celnum;
Qcopchannel: Send ("/system/temperature", "convertceltofah (INT)", data ); } # Include <qapplication> # Include "cel. H" Int main (INT argc, char * argv []) { Qapplication app (argc, argv/*, qapplication: guiclient */); Cel screen; Screen. setgeometry (0, 25,100,250 ); Screen. Show (); Return app.exe C (); } |