I have been buying a Development Board for three months and can finally make some small things.
But I forgot later, so I decided to start taking notes. I hope to communicate with csdn
My Development Board runs the kernel of linux2.6.24, qtopia for GUI, so QT for development tools.
At first, I could not understand the book I borrowed from QT. Later I followed the example in the document and found that QT is actually not difficult and powerful.
This is a small program written with QT today. Its function is very simple. It is a simple clock, reads the system time, and updates it once a second.
Clock. h // clock class declaration and header file inclusion
Code:
- # Include <qapplication. h>
- # Include <qsound. h>
- # Include <qlabel. h>
- # Include <qdatetime. h>
- # Include <qstring. h>
- # Include <qnamespace. h>
- # Include <qfont. h>
- # Include <qtimer. h>
- Class clock: Public qwidget
- {
- Q_object
- Public:
- Clock (qwidget * parent = 0, const char * name = 0 );
- Public slots:
- Void repainttime ();
- PRIVATE:
- Qtime nowtime;
- Qstring time;
- Qlabel * label;
- };
Clock. cpp // clock implementation
Code:
- # Include "clock. H"
- Clock: Clock (qwidget * parent, const char * Name): qwidget (parent, name)
- {
- Label = new qlabel ("", this );
- Qtimer * timer = new qtimer (this );
- Connect (timer, signal (timeout (), this, slot (repainttime ()));
- Label-& gt; resize (100,100 );
- Label-> setfont (qfont ("Times", 18, qfont: bold ));
- Nowtime = qtime: currenttime ();
- Time = nowtime. tostring ();
- Label-> settext (time );
- Timer-> Start (1000, false );
- }
- Void clock: repainttime ()
- {
- Nowtime = qtime: currenttime ();
- Time = nowtime. tostring ();
- Label-> settext (time );
- }
Main. cpp Main Function
Code:
- # Include "clock. H"
- Int main (INT argc, char ** argv)
- {
- Qapplication app (argc, argv );
- Clock;
- App. setmainwidget (& clock );
- Clock. Show ();
- Return app.exe C ();
- }
Next, I plan to use the buzzer to make a simulated alarm.
Write a little bit every day, the program will get bigger and bigger