QtEmbedded n n n n QtEmbedded qtembeddedfree3 3
Qt/Embedded 개요 n 강의 홈페이지에서 다운로드할 파일 n n n Qt/Embedded: qt-embedded-free-3. 3. 3. tr. bz 2 Qt 라이브러리: qt_lib. zip Qt 도구(qvfb, uic): source 1. tar
실습 Qt/Embedded 환경 설정 n ⑥ #gedit ~/. bash_profile n n n ⑧ #gedit src/embedded/qmouselinuxtp_qws. cpp
n 11 12 …… 20 21 22 23 24 25 26 27 28 29 30 31 …… 35 36 37 38 39 40 41 Qt/Embedded 응용 프로그램(main. cpp) #include "hello. h" #include <qapplication. h> int main( int argc, char **argv ) { QApplication a(argc, argv); QString s; for ( int i=1; i<argc; i++ ) { s += argv[i]; if ( i<argc-1 ) s += " "; } if ( s. is. Empty() ) s = "Hello, World"; Hello h( s ); QObject: : connect( &h, SIGNAL(clicked()), &a, SLOT(quit()) ); h. set. Font( QFont("times", 32, QFont: : Bold) ); // default font h. set. Background. Color( Qt: : white ); // default bg color a. set. Main. Widget( &h ); h. show(); return a. exec(); }
n 10 …… 20 21 22 23 24 25 26 27 28 …… 35 36 37 38 39 …… 48 49 50 51 52 …… 61 62 63 64 65 66 67 68 Qt/Embedded 응용 프로그램(hello. cpp) #include "hello. h" Hello: : Hello( const char *text, QWidget *parent, const char *name ) : QWidget(parent, name), t(text), b(0) { QTimer *timer = new QTimer(this); connect( timer, SIGNAL(timeout()), SLOT(animate()) ); timer->start( 40 ); resize( 260, 130 ); } void Hello: : animate() { b = (b + 1) & 15; repaint( FALSE ); } void Hello: : mouse. Release. Event( QMouse. Event *e ) { if ( rect(). contains( e->pos() ) ) emit clicked(); } void Hello: : paint. Event( QPaint. Event * ) { static int sin_tbl[16] = { 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38}; if ( t. is. Empty() ) return;
n 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 Qt/Embedded 응용 프로그램(hello. cpp) // 1: Compute some sizes, positions etc. QFont. Metrics fm = font. Metrics(); int w = fm. width(t) + 20; int h = fm. height() * 2; int pmx = width()/2 - w/2; int pmy = height()/2 - h/2; // 2: Create the pixmap and fill it with the widget's background QPixmap pm( w, h ); pm. fill( this, pmx, pmy ); // 3: Paint the pixmap. Cool wave effect QPainter p; int x = 10; int y = h/2 + fm. descent(); int i = 0; p. begin( &pm ); p. set. Font( font() ); while ( !t[i]. is. Null() ) { int i 16 = (b+i) & 15; p. set. Pen( QColor((15 -i 16)*16, 255, QColor: : Hsv) ); p. draw. Text( x, y-sin_tbl[i 16]*h/800, t. mid(i, 1), 1 ); x += fm. width( t[i] ); i++; } p. end(); // 4: Copy the pixmap to the Hello widget bit. Blt( this, pmx, pmy, &pm ); }
실습 FND 제어용 HTML 문서 작성(fnd. htm) 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 <html> <head><title>Web Server Application</title></head> <body> <H 1>Web Server Application</H 1> <form method="GET" action="cgi-bin/fnd"> Enter a 8 -digit number: <input name="send_number" maxlength="8" type="text" size="20"> <input type="submit" value="SEND"> </form> Then see the FND device on the taget system. </body> </html>
실습 FND 디바이스 제어용 CGI 프로그램 작성(fnd. c) 016 …… 025 026 027 028 029 030 031 032 033 034 035 …… 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 …… #include <stdio. h> static char fnd. Dev[] = "/dev/FND"; static int fnd. Fd = (-1); asc 2 fnd(char *s, long n) { char c; int l; while (n > 0) { l = n % 10; switch (l) { case 0: c = 0 x 3 f; break; } } } *s++ = c; n = n/10; int send_number_FND(long av) { int n; char buf[MAXFND+1]; fnd. Fd = open( fnd. Dev, O_RDWR); if (fnd. Fd < 0) { fprintf(stderr, "cannot open FND (%d)", fnd. Fd); exit(2); } memset(buf, 0, sizeof(buf)); } asc 2 fnd(buf, av); write(fnd. Fd, buf, MAXFND); return 0;
실습 FND 디바이스 제어용 CGI 프로그램 작성(fnd. c) 073 074 075 076 …… 082 …… 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 int main(int argc, char *argv[]) { char *cgiinput ; long send_number; printf("Content-type: text/html; charset=iso-8859 -1%c%cnn", 13, 10) ; printf("<html>n"); printf("<head><title>Web Server Application</title></head>n"); printf("<body>n"); printf("<H 1>Web Server Application</H 1>n"); cgiinput= getenv("QUERY_STRING"); if(cgiinput == NULL) printf("<P>Error in passing data from form to script. "); else if(sscanf(cgiinput, "send_number=%ld", &send_number)!=1) printf("<P>Invalid data. Data must be numeric. "); else send_number_FND(send_number); printf("<center> Check the FND, [%ld] is displayed</center>n", send_number); printf("</body>n"); printf("</html>n"); return 0; }
- Slides: 35