Learning notes: a qt applet that runs successfully on the Development Board

Source: Internet
Author: User

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:
  1. # Include <qapplication. h>
  2. # Include <qsound. h>
  3. # Include <qlabel. h>
  4. # Include <qdatetime. h>
  5. # Include <qstring. h>
  6. # Include <qnamespace. h>
  7. # Include <qfont. h>
  8. # Include <qtimer. h>
  9. Class clock: Public qwidget
  10. {
  11. Q_object
  12. Public:
  13. Clock (qwidget * parent = 0, const char * name = 0 );
  14. Public slots:
  15. Void repainttime ();
  16. PRIVATE:
  17. Qtime nowtime;
  18. Qstring time;
  19. Qlabel * label;
  20. };

Clock. cpp // clock implementation

Code:
  1. # Include "clock. H"
  2. Clock: Clock (qwidget * parent, const char * Name): qwidget (parent, name)
  3. {
  4. Label = new qlabel ("", this );
  5. Qtimer * timer = new qtimer (this );
  6. Connect (timer, signal (timeout (), this, slot (repainttime ()));
  7. Label-& gt; resize (100,100 );
  8. Label-> setfont (qfont ("Times", 18, qfont: bold ));
  9. Nowtime = qtime: currenttime ();
  10. Time = nowtime. tostring ();
  11. Label-> settext (time );
  12. Timer-> Start (1000, false );
  13. }
  14. Void clock: repainttime ()
  15. {
  16. Nowtime = qtime: currenttime ();
  17. Time = nowtime. tostring ();
  18. Label-> settext (time );
  19. }

Main. cpp Main Function

Code:
  1. # Include "clock. H"
  2. Int main (INT argc, char ** argv)
  3. {
  4. Qapplication app (argc, argv );
  5. Clock;
  6. App. setmainwidget (& clock );
  7. Clock. Show ();
  8. Return app.exe C ();
  9. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.