~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qt4-intro.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/doc/src/qt4-intro.qdoc -->
 
6
<head>
 
7
    <title>Qt 4.0: What's New in Qt 4</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
    <link rel="next" href="qt4-tulip.html" />
 
15
    <link rel="start" href="index.html" />
 
16
</head>
 
17
<body>
 
18
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
19
<tr>
 
20
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
21
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
22
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><p>
 
23
[Next: <a href="qt4-tulip.html">The Tulip Container Classes</a>]
 
24
</p>
 
25
<h1 align="center">What's New in Qt 4</h1>
 
26
<p>This document covers the most important differences between Qt 3 and Qt 4. Although it is not intended to be a comprehensive porting guide, it tells you about the most important portability issues that you may encounter. It also explains how to turn on Qt 3 compatibility support.</p>
 
27
<ul><li><a href="#new-technologies">New Technologies</a></li>
 
28
<li><a href="#build-system">Build System</a></li>
 
29
<li><a href="#include-syntax">Include Syntax</a></li>
 
30
<li><a href="#namespaces">Namespaces</a></li>
 
31
<li><a href="#qobject-qwidget-constructors">QObject/QWidget Constructors</a></li>
 
32
<li><a href="#dynamic-casts">Dynamic Casts</a></li>
 
33
<li><a href="#qpointer-t">QPointer&lt;T&gt;</a></li>
 
34
<li><a href="#paint-events">Paint Events</a></li>
 
35
<li><a href="#qt-3-support-layer">Qt 3 Support Layer</a></li>
 
36
<li><a href="#supported-platforms">Supported Platforms</a></li>
 
37
</ul>
 
38
<a name="new-technologies"></a>
 
39
<h2>New Technologies</h2>
 
40
<p>Qt 4 introduces the following core technologies:</p>
 
41
<ul>
 
42
<li><a href="qt4-tulip.html">Tulip</a>, a new set of template container classes.</li>
 
43
<li><a href="qt4-interview.html">Interview</a>, a model/view architecture for item views.</li>
 
44
<li><a href="qt4-arthur.html">Arthur</a>, the Qt 4 painting framework.</li>
 
45
<li><a href="qt4-scribe.html">Scribe</a>, the Unicode text renderer with a public API for performing low-level text layout.</li>
 
46
<li><a href="qt4-mainwindow.html">Mainwindow</a>, a modern action-based mainwindow, toolbar, menu, and docking architecture.</li>
 
47
</ul>
 
48
<p>Qt 4 also includes the new <i>Qt Designer</i> user interface design tool. See the <a href="qt4-designer.html">Qt Designer overview</a> to get started.</p>
 
49
<p>In addition, the following modules have been significantly improved since Qt 3:</p>
 
50
<ul>
 
51
<li>A fully cross-platform <a href="accessibility.html">accessibility</a> module, with support for the emerging SP-API Unix standard in addition to Microsoft and Mac Accessibility.</li>
 
52
<li>The <a href="qt4-sql.html">SQL module</a>, which is now based on the Interview model/view framework.</li>
 
53
<li>The <a href="qt4-network.html">network module</a>, with better support for UDP and synchronous sockets.</li>
 
54
<li>The <a href="qt4-styles.html">style API</a>, which is now decoupled from the widgets, meaning that you can draw any user interface element on any device (widget, pixmap, etc.).</li>
 
55
<li>Enhanced <a href="qt4-threads.html">thread support</a>, with signal-slot connections across threads and per-thread event loops.</li>
 
56
<li>A new <a href="resources.html">resource system</a> for embedding images and other resource files into the application executable.</li>
 
57
</ul>
 
58
<a name="build-system"></a>
 
59
<h2>Build System</h2>
 
60
<p>Unlike previous Qt releases, Qt 4 is a collection of smaller libraries:</p>
 
61
<table align="center" cellpadding="2" cellspacing="1" border="0">
 
62
<tr valign="top" bgcolor="#a2c511"><th>Library</th><th>Description</th></tr>
 
63
<tr valign="top" bgcolor="#f0f0f0"><td><a href="qtcore.html#qtcore">QtCore</a></td><td>Core non-GUI functionality</td></tr>
 
64
<tr valign="top" bgcolor="#e0e0e0"><td><a href="qtgui.html#qtgui">QtGui</a></td><td>Core GUI functionality</td></tr>
 
65
<tr valign="top" bgcolor="#f0f0f0"><td><a href="qtnetwork.html#qtnetwork">QtNetwork</a></td><td>Network module</td></tr>
 
66
<tr valign="top" bgcolor="#e0e0e0"><td><a href="qtopengl.html#qtopengl">QtOpenGL</a></td><td>OpenGL module</td></tr>
 
67
<tr valign="top" bgcolor="#f0f0f0"><td><a href="qtsql.html#qtsql">QtSql</a></td><td>SQL module</td></tr>
 
68
<tr valign="top" bgcolor="#e0e0e0"><td><a href="qtxml.html#qtxml">QtXml</a></td><td>XML module</td></tr>
 
69
<tr valign="top" bgcolor="#f0f0f0"><td><a href="qt3support.html#qt3support">Qt3Support</a></td><td>Qt 3 support classes</td></tr>
 
70
<tr valign="top" bgcolor="#e0e0e0"><td><a href="qaxcontainer.html#qaxcontainer">QAxContainer</a></td><td><a href="activeqt.html#activeqt">ActiveQt</a> client extension</td></tr>
 
71
<tr valign="top" bgcolor="#f0f0f0"><td><a href="qaxserver.html#qaxserver">QAxServer</a></td><td><a href="activeqt.html#activeqt">ActiveQt</a> server extension</td></tr>
 
72
<tr valign="top" bgcolor="#e0e0e0"><td><a href="qtdesigner.html#qtdesigner">QtDesigner</a></td><td>Classes for extending and embedding Qt Designer</td></tr>
 
73
</table>
 
74
<p><a href="qtcore.html#qtcore">QtCore</a> contains tool classes like <a href="qstring.html">QString</a>, <a href="qlist.html">QList</a>, and <a href="qfile.html">QFile</a>, as well as kernel classes like <a href="qobject.html">QObject</a> and <a href="qtimer.html">QTimer</a>. The <a href="qapplication.html">QApplication</a> class has been refactored so that it can be used in non-GUI applications. It is split into <a href="qcoreapplication.html">QCoreApplication</a> (in <a href="qtcore.html#qtcore">QtCore</a>) and <a href="qapplication.html">QApplication</a> (in <a href="qtgui.html#qtgui">QtGui</a>).</p>
 
75
<p>This split makes it possible to develop server applications using Qt without linking in any unnecessary GUI-related code and without requiring GUI-related system libraries to be present on the target machine (e.g. Xlib on <a href="winsystem.html#x11">X11</a>, Carbon on Mac OS X).</p>
 
76
<p>If you use qmake to generate your makefiles, qmake will by default link your application against <a href="qtcore.html#qtcore">QtCore</a> and <a href="qtgui.html#qtgui">QtGui</a>. To remove the dependency upon <a href="qtgui.html#qtgui">QtGui</a>, add the line</p>
 
77
<pre>&nbsp;   QT -= gui</pre>
 
78
<p>to your .pro file. To enable the other libraries, add the line</p>
 
79
<pre>&nbsp;   QT += network opengl sql qt3support</pre>
 
80
<p>Another change to the build system is that moc now understands preprocessor directives. qmake automatically passes the defines set for your project (using &quot;DEFINES +=&quot;) on to moc, which has its own built-in C++ preprocessor.</p>
 
81
<p>To compile code that uses .ui files, you will also need this line in the .pro file:</p>
 
82
<pre>&nbsp;   CONFIG += uic3</pre>
 
83
<a name="include-syntax"></a>
 
84
<h2>Include Syntax</h2>
 
85
<p>The syntax for including Qt class definitions has become</p>
 
86
<pre>&nbsp;   #include &lt;QClassName&gt;</pre>
 
87
<p>For example:</p>
 
88
<pre>&nbsp;   #include &lt;QString&gt;
 
89
    #include &lt;QApplication&gt;
 
90
    #include &lt;QSqlTableModel&gt;</pre>
 
91
<p>This is guaranteed to work for any public Qt class. The old syntax,</p>
 
92
<pre>&nbsp;   #include &lt;qclassname.h&gt;</pre>
 
93
<p>still works, but we encourage you to switch to the new syntax.</p>
 
94
<p>If you attempt to include a header file from a library that isn't linked against the application, this will result in a compile-time warning (e.g., &quot;<a href="qsqlquery.html">QSqlQuery</a>: No such file or directory&quot;). You can remedy to this problem either by removing the offending include or by specifying the missing library in the QT entry of your <tt>.pro</tt> file (see <a href="#build-system">Build System</a> above).</p>
 
95
<p>To include the definitions for all the classes in a library, simply specify the name of that library. For example:</p>
 
96
<pre>&nbsp;   #include &lt;QtCore&gt;</pre>
 
97
<a name="namespaces"></a>
 
98
<h2>Namespaces</h2>
 
99
<p>Qt 2 introduced a class called Qt for global-like constants (e.g., <tt>Qt::yellow</tt>). The C++ namespace construct was not used because not all compilers understood it when it was released.</p>
 
100
<p>With Qt 4, the Qt class has become the Qt namespace. If you want to access a constant that is part of the Qt namespace, prefix it with <tt>Qt:</tt>: (e.g., <tt>Qt::yellow</tt>), or add the directive</p>
 
101
<pre>&nbsp;   using namespace Qt;</pre>
 
102
<p>at the top of your source files, after your <tt>#include</tt> directives. If you use the <tt>using namespace</tt> syntax you don't need the prefix (e.g., <tt>yellow</tt> is sufficient).</p>
 
103
<p>When porting Qt 3 applications, you may run into some source compatibility problems with some of these symbols. For example, in Qt 3, it was legal to write <tt>QWidget::yellow</tt> instead of <tt>Qt::yellow</tt>, because <a href="qwidget.html">QWidget</a> inherited from Qt. This won't work in Qt 4; you must write <tt>Qt::yellow</tt> or add the &quot;using namespace&quot; directive and drop the <tt>Qt:</tt>: prefix.</p>
 
104
<p>The <a href="qt3to4.html">qt3to4 porting tool</a> automates this conversion.</p>
 
105
<a name="qobject-qwidget-constructors"></a>
 
106
<h2>QObject/QWidget Constructors</h2>
 
107
<p>In Qt 4 we have tried to simplify the constructors of <a href="qobject.html">QObject</a>/<a href="qwidget.html">QWidget</a> subclasses. This makes subclassing easier, at the same time as it helps make the Qt library more efficient.</p>
 
108
<p>Constructors no longer take a &quot;const char *name&quot; parameter. If you want to specify a name for a <a href="qobject.html">QObject</a>, you must call <a href="qobject.html#objectName-prop">QObject::setObjectName</a>() after construction. The object name is now a <a href="qstring.html">QString</a>.</p>
 
109
<p><a href="qwidget.html">QWidget</a>'s <tt>WFlags</tt> data type has been split in two: <a href="qt.html#WindowType-enum">Qt::WindowFlags</a> specifies low-level window flags (the type of window and the frame style), whereas <a href="qt.html#WidgetAttribute-enum">Qt::WidgetAttribute</a> specifies various higher-level attributes about the widget (e.g., WA_StaticContents). Widget attributes can be set at any time using <a href="qwidget.html#setAttribute">QWidget::setAttribute</a>(); low-level window flags can be passed to the <a href="qwidget.html">QWidget</a> constructor or set later using <a href="qwidget.html#setParent">QWidget::setParent</a>(). As a consequence, the constructors of most <a href="qwidget.html">QWidget</a> subclasses don't need to provide a <tt>WFlags</tt> parameter.</p>
 
110
<p>The <i>parent</i> parameter of all <a href="qobject.html">QObject</a> classes in Qt defaults to a null pointer, as it used to do in Qt 1. This enables a style of programming where widgets are created without parents and then inserted in a layout, at which point the layout automatically reparents them.</p>
 
111
<a name="dynamic-casts"></a>
 
112
<h2>Dynamic Casts</h2>
 
113
<p>Qt 4 provides a qobject_cast&lt;&gt;() function that performs a dynamic cast based on the meta-information generated by moc for <a href="qobject.html">QObject</a> subclasses. Unlike the standard C++ <a href="#dynamic-casts">dynamic_cast</a>&lt;&gt;() construct, qobject_cast&lt;&gt;() works even when RTTI is disabled, and it works correctly across DLL boundaries.</p>
 
114
<p>Here's the Qt 3 idiom to cast a type to a subtype:</p>
 
115
<pre>&nbsp;   // DEPRECATED
 
116
    if (obj-&gt;inherits(&quot;QPushButton&quot;)) {
 
117
        QPushButton *pushButton = (QPushButton *)obj;
 
118
        ...
 
119
    }</pre>
 
120
<p>The Qt 4 idiom is both cleaner and safer, because typos will always result in compiler errors:</p>
 
121
<pre>&nbsp;   QPushButton *pushButton = qobject_cast&lt;QPushButton *&gt;(obj);
 
122
    if (pushButton) {
 
123
        ...
 
124
    }</pre>
 
125
<a name="qpointer-t"></a>
 
126
<h2>QPointer&lt;T&gt;</h2>
 
127
<p>The <a href="qpointer.html">QPointer</a>&lt;T&gt; class provides a pointer to type T (where T inherits from <a href="qobject.html">QObject</a>) that is automatically set to 0 when the referenced object is destroyed. Guarded pointers are useful whenever you want to store a pointer to an object you do not own.</p>
 
128
<p>Example:</p>
 
129
<pre>&nbsp;   QLabel *label = new QLabel;
 
130
    QPointer&lt;QLabel&gt; safeLabel = label;
 
131
    safeLabel-&gt;setText(&quot;Hello world!&quot;);
 
132
    delete label;
 
133
    // safeLabel is now 0, whereas label is a dangling pointer</pre>
 
134
<p><a href="qpointer.html">QPointer</a>&lt;T&gt; is more or less the same as the old QGuardedPtr&lt;T&gt; class, except that it is now implemented in a much more lightweight manner than before. The cost of one <a href="qpointer.html">QPointer</a>&lt;T&gt; object is now approximately the same as that of a signal--slot connection.</p>
 
135
<a name="paint-events"></a>
 
136
<h2>Paint Events</h2>
 
137
<p>Qt 4 supports double buffering transparently on all platforms. This feature can be turned off on a per-widget basis by calling QWidget::setAttribute(<a href="qt.html#WidgetAttribute-enum">Qt::WA_PaintOnScreen</a>).</p>
 
138
<p>A consequence of this is that all painting must now be done from the paintEvent() function. This is also required by the HIView API on Mac OS X. In practice, this is seldom a problem, since you can call update() from anywhere in your code to create a paint event, with the region to update as the argument.</p>
 
139
<p>To help porting, <a href="qwidget.html">QWidget</a> supports a <a href="qt.html#WidgetAttribute-enum">Qt::WA_PaintOutsidePaintEvent</a> attribute that can be set to make it possible to paint outside <a href="qwidget.html#paintEvent">paintEvent()</a> on Windows and <a href="winsystem.html#x11">X11</a>.</p>
 
140
<a name="qt-3-support-layer"></a>
 
141
<h2>Qt 3 Support Layer</h2>
 
142
<p>Qt 4 provides an extension library that applications based on Qt 3, called <a href="qt3support.html#qt3support">Qt3Support</a>, that Qt applications can link against. This allows for more compatibility than ever before, without bloating Qt.</p>
 
143
<ul>
 
144
<li>Classes that have been replaced by a different class with the same name, such as <a href="qlistview.html">QListView</a>, and classes that no longer exist in Qt 4 are available with a <tt>3</tt> in their name (e.g., <a href="q3listview.html">Q3ListView</a>, <a href="q3accel.html">Q3Accel</a>).</li>
 
145
<li>Other classes provide compatibility functions. Most of these are implemented inline, so that they don't bloat the Qt libraries.</li>
 
146
</ul>
 
147
<p>To enable the Qt 3 support classes and functions, add the line</p>
 
148
<pre>&nbsp;   QT += qt3support</pre>
 
149
<p>to your <tt>.pro</tt> file.</p>
 
150
<p>On Visual C++ 7 and GCC 3.2+, using compatibility functions often results in a compiler warning (e.g., &quot;'find' is deprecated&quot;). If you want to turn off that warning, add the line</p>
 
151
<pre>&nbsp;   DEFINES += QT3_SUPPORT</pre>
 
152
<p>to your <tt>.pro</tt> file.</p>
 
153
<p>If you want to use compatibility functions but don't want to link against the <a href="qt3support.html#qt3support">Qt3Support</a> library, add the line</p>
 
154
<pre>&nbsp;   DEFINES += QT3_SUPPORT_WARNINGS</pre>
 
155
<p>or</p>
 
156
<pre>&nbsp;   DEFINES += QT3_SUPPORT</pre>
 
157
<p>to your <tt>.pro</tt> file, depending on whether you want compatibility function calls to generate compiler warnings or not.</p>
 
158
<a name="supported-platforms"></a>
 
159
<h2>Supported Platforms</h2>
 
160
<p>See <a href="http://www.trolltech.com/products/qt/qt4-platforms.html">Trolltech's web site</a> for more information on the planned supported platforms for Qt 4.0.</p>
 
161
<p>
 
162
[Next: <a href="qt4-tulip.html">The Tulip Container Classes</a>]
 
163
</p>
 
164
<p /><address><hr /><div align="center">
 
165
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
166
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
167
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
168
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
169
</tr></table></div></address></body>
 
170
</html>