1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 99 100 101 102 103 104 105 106 107 108 109 110
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Tutorial - t12/main.cpp</title>
</head><body bgcolor="#ffffff">
<p>
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<p>
<h1 align=center>Source code for <a href="t12.html">tutorial 12</a>: main.cpp</h1><br clear="all">
<hr> <pre>/****************************************************************
**
** Qt tutorial 12
**
****************************************************************/
#include <<a href="qapplication-h.html">qapplication.h</a>>
#include <<a href="qpushbutton-h.html">qpushbutton.h</a>>
#include <<a href="qlcdnumber-h.html">qlcdnumber.h</a>>
#include <<a href="qfont-h.html">qfont.h</a>>
#include <<a href="qlayout-h.html">qlayout.h</a>>
#include "lcdrange.h"
#include "cannon.h"
class MyWidget: public QWidget
{
public:
MyWidget( <a href="qwidget.html">QWidget</a> *parent=0, const char *name=0 );
};
MyWidget::MyWidget( <a href="qwidget.html">QWidget</a> *parent, const char *name )
: <a href="qwidget.html">QWidget</a>( parent, name )
{
<a href="qpushbutton.html">QPushButton</a> *quit = new <a href="qpushbutton.html">QPushButton</a>( "&Quit", this, "quit" );
quit-><a href="qwidget.html#c52788">setFont</a>( <a href="qfont.html">QFont</a>( "Times", 18, QFont::Bold ) );
<a href="qobject.html#7f8e37">connect</a>( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );
LCDRange *angle = new LCDRange( "ANGLE", this, "angle" );
angle->setRange( 5, 70 );
LCDRange *force = new LCDRange( "FORCE", this, "force" );
force->setRange( 10, 50 );
CannonField *cannonField = new CannonField( this, "cannonField" );
<a href="qobject.html#7f8e37">connect</a>( angle, SIGNAL(valueChanged(int)),
cannonField, SLOT(setAngle(int)) );
<a href="qobject.html#7f8e37">connect</a>( cannonField, SIGNAL(angleChanged(int)),
angle, SLOT(setValue(int)) );
<a href="qobject.html#7f8e37">connect</a>( force, SIGNAL(valueChanged(int)),
cannonField, SLOT(setForce(int)) );
<a href="qobject.html#7f8e37">connect</a>( cannonField, SIGNAL(forceChanged(int)),
force, SLOT(setValue(int)) );
<a href="qpushbutton.html">QPushButton</a> *shoot = new <a href="qpushbutton.html">QPushButton</a>( "&Shoot", this, "shoot" );
shoot-><a href="qwidget.html#c52788">setFont</a>( <a href="qfont.html">QFont</a>( "Times", 18, QFont::Bold ) );
<a href="qobject.html#7f8e37">connect</a>( shoot, SIGNAL(clicked()), cannonField, SLOT(shoot()) );
<a href="qgridlayout.html">QGridLayout</a> *grid = new <a href="qgridlayout.html">QGridLayout</a>( this, 2, 2, 10 );
grid-><a href="qgridlayout.html#dac29c">addWidget</a>( quit, 0, 0 );
grid-><a href="qgridlayout.html#dac29c">addWidget</a>( cannonField, 1, 1 );
grid-><a href="qgridlayout.html#df80c4">setColStretch</a>( 1, 10 );
<a href="qvboxlayout.html">QVBoxLayout</a> *leftBox = new <a href="qvboxlayout.html">QVBoxLayout</a>;
grid-><a href="qgridlayout.html#a409bc">addLayout</a>( leftBox, 1, 0 );
leftBox-><a href="qboxlayout.html#ebba99">addWidget</a>( angle );
leftBox-><a href="qboxlayout.html#ebba99">addWidget</a>( force );
<a href="qhboxlayout.html">QHBoxLayout</a> *topBox = new <a href="qhboxlayout.html">QHBoxLayout</a>;
grid-><a href="qgridlayout.html#a409bc">addLayout</a>( topBox, 0, 1 );
topBox-><a href="qboxlayout.html#ebba99">addWidget</a>( shoot );
topBox-><a href="qboxlayout.html#0226eb">addStretch</a>( 1 );
angle->setValue( 60 );
force->setValue( 25 );
angle-><a href="qwidget.html#25775a">setFocus</a>();
}
int main( int argc, char **argv )
{
<a href="qapplication.html#1ee2d1">QApplication::setColorSpec</a>( QApplication::CustomColor );
<a href="qapplication.html">QApplication</a> a( argc, argv );
MyWidget w;
w.<a href="qwidget.html#9ede68">setGeometry</a>( 100, 100, 500, 355 );
a.<a href="qapplication.html#7ad759">setMainWidget</a>( &w );
w.<a href="qwidget.html#200ee5">show</a>();
return a.<a href="qapplication.html#84c7bf">exec</a>();
}
</pre>
<p>
<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>
|