Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 2192

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/doc/tutorial.doc:80 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Tutorial - Chapter 1: Hello, World!</title>
<style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Qt Tutorial - Chapter 1: Hello, World!</h1>

 
<p> <center><img src="t1.png" alt="Screenshot of tutorial one"></center>
<p> This first program is a simple hello-world example.  It contains only
the bare minimum you need to get a Qt application up and running.
The picture above is a snapshot of this program.
<p> <pre>/****************************************************************
**
** Qt tutorial 1
**
****************************************************************/

#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
#include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;


int main( int argc, char **argv )
{
    <a href="qapplication.html">QApplication</a> a( argc, argv );

    <a href="qpushbutton.html">QPushButton</a> hello( "Hello world!", 0 );
    hello.<a href="qwidget.html#resize">resize</a>( 100, 30 );

    a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;hello );
    hello.<a href="qwidget.html#show">show</a>();
    return a.<a href="qapplication.html#exec">exec</a>();
}
</pre>



<p> <h2> Line-by-line Walkthrough
</h2>
<a name="1"></a><p> <pre>    #include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;
</pre>
<p> This line includes the <a href="qapplication.html">QApplication</a> class definition.  There has to be
exactly one QApplication object in every application that uses Qt.
QApplication manages various application-wide resources, such as the
default font and cursor.
<p> <pre>    #include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;
</pre>
<p> This line includes the <a href="qpushbutton.html">QPushButton</a> class definition.  The
<a href="hierarchy.html">reference documentation</a> for each class
mentions at the top which file needs to be included to use that class.
<p> QPushButton is a classical GUI push button that the user can press
and release.  It manages its own look and feel, like every other <a href="qwidget.html">QWidget</a>.  A widget is a user interface object that can process user
input and draw graphics.  The programmer can change both the overall
<a href="qapplication.html#setStyle">look and feel</a> and many minor
properties of it (such as color), as well as the widget's content.  A
QPushButton can show either a text or a <a href="qpixmap.html">QPixmap</a>.
<p> <pre>    int main( int argc, char **argv )
    {
</pre>
<p> The main() function is the entry point to the program.  Almost always
when using Qt, main() only needs to perform some kind of initialization
before passing the control to the Qt library, which then tells the
program about the user's actions via events.
<p> <tt>argc</tt> is the number of command-line arguments and <tt>argv</tt> is the
array of command-line arguments.  This is a C/C++ feature.  It is not
specific to Qt; however, Qt needs to process these arguments (see
following).
<p> <pre>        <a href="qapplication.html">QApplication</a> a( argc, argv );
</pre>
<p> <tt>a</tt> is this program's <a href="qapplication.html">QApplication</a>.  Here it is created and processes
some of the command-line arguments (such as -display under X Window).
Note that all command-line arguments recognized by Qt are removed from
<tt>argv</tt> (and <tt>argc</tt> is decremented accordingly).  See the <a href="qapplication.html#argv">QApplication::argv</a>() documentation for details.
<p> <strong>Note:</strong> It is essential that the QApplication object be
created before any window-system parts of Qt are used.
<p> <pre>        <a href="qpushbutton.html">QPushButton</a> hello( "Hello world!", 0 );
</pre>
<p> Here, <em>after</em> the QApplication, comes the first window-system code: A
push button is created.
<p> The button is set up to display the text "Hello world!" and be a
window of its own (because the constructor specifies 0 for the parent
window, inside which the button should be located).
<p> <pre>    <a name="x2098"></a>    hello.<a href="qwidget.html#resize">resize</a>( 100, 30 );
</pre>
<p> The button is set up to be 100 pixels wide and 30 pixels high (plus the
window system frame).  In this case we don't care about the button's
position, and we accept the default value.
<p> <pre>    <a name="x2097"></a>    a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;hello );
</pre>
<p> The push button is chosen as the main widget for the application.  If
the user closes a main widget, the application exits.
<p> You don't have to have a main widget, but most programs do have one.
<p> <pre>    <a name="x2099"></a>    hello.<a href="qwidget.html#show">show</a>();
</pre>
<p> A widget is never visible when you create it.  You must call show() to
make it visible.
<p> <pre>    <a name="x2096"></a>    return a.<a href="qapplication.html#exec">exec</a>();
</pre>
<p> This is where main() passes control to Qt, and exec() will return when
the application exits.
<p> In exec(), Qt receives and processes user and system events and passes
these on to the appropriate widgets.
<p> <pre>    }
</pre>
<p> <h2> Behavior
</h2>
<a name="2"></a><p> You should now try to compile and run this program.
<p> When you run it, you will see a small window filled with a single
button, and on it you can read the famous words, Hello World!
<p> <h2> Exercises
</h2>
<a name="3"></a><p> Try to resize the window.  Press the button.  If you're running X
Window, try running the program with the -geometry option
(for example, <tt>-geometry 100x200+10+20</tt>).
<p> You may now go on to <a href="t2.html">Chapter 2.</a>
<p> [<a href="t2.html">Next tutorial</a>]
[<a href="tutorial.html">Main tutorial page</a>]
<p> 
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>