source: trunk/doc/src/qt4-intro.qdoc@ 762

Last change on this file since 762 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 36.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*!
43 \page qt4-intro.html
44 \title What's New in Qt 4
45
46 \startpage index.html Qt Reference Documentation
47 \nextpage The Tulip Container Classes
48
49 This document covers the most important differences between Qt 3
50 and Qt 4. Although it is not intended to be a comprehensive
51 porting guide, it tells you about the most important portability
52 issues that you may encounter. It also explains how to turn on Qt
53 3 compatibility support.
54
55 \tableofcontents
56
57 \section1 New Technologies in Qt 4
58
59 Qt 4 introduces the following core technologies:
60
61 \list
62 \o \l{The Tulip Container Classes}{Tulip}, a new set of template container classes.
63
64 \o \l{The Interview Framework}{Interview}, a model/view architecture for item views.
65
66 \o \l{The Arthur Paint System}{Arthur}, the Qt 4 painting framework.
67
68 \o \l{The Scribe Classes}{Scribe}, the Unicode text renderer with a public API
69 for performing low-level text layout.
70
71 \o \l{The Qt 4 Main Window Classes}{Mainwindow}, a modern action-based
72 mainwindow, toolbar, menu, and docking architecture.
73
74 \o The new \l{The New Qt Designer}{\QD} user interface design tool.
75 \endlist
76
77 \section1 Recent Additions to Qt 4
78
79 The following features have been added to Qt since the first release of Qt 4:
80
81 In Qt 4.5:
82 \list
83 \o The WebKit browser engine included with Qt has been
84 upgraded to the latest upstream (trunk) version of WebKit,
85 bringing the latest features and improvements to Qt applications.
86 \o Qt for Mac OS X has been substantially rewritten to use
87 Apple's Cocoa API, enabling Qt applications to be deployed on
88 64-bit Macintosh hardware.
89 \o The QtXmlPatterns module has been extended to cover XSLT, a
90 transformation language for XML documents.
91 \o Qt Script introduced its debugger,
92 providing error reporting for scripts, and to let users track down
93 bugs in their own scripts.
94 \o Qt 4.5 includes support for writing rich text documents as
95 OpenDocument files via the newly-introduced QTextDocumentWriter
96 class.
97 \o Qt Linguist can load and edit multiple translation
98 files simultaneously.
99 \o Support for ARGB top-level widgets (i.e., translucent
100 windows).
101 \endlist
102
103 In Qt 4.4:
104 \list
105 \o \l{QtWebkit Module}{Qt WebKit integration}, making it possible for developers
106 to use a fully-featured Web browser to display documents and access online
107 services.
108 \o A multimedia API provided by the \l{Phonon Overview}{Phonon Multimedia Framework}.
109 \o \l{QtXmlPatterns Module}{XQuery and XPath} support, providing facilities for
110 XML processing beyond that supported by the QtXml module.
111 \o Support for embedded widgets in \l{Graphics View} scenes.
112 \o The \l{Thread Support in Qt}{QtConcurrent framework} for
113 concurrent programming using Qt paradigms and threading features.
114 \o An \l{QtHelp Module}{improved help system} that can be used in conjunction
115 with Qt Assistant or as an independent help resource manager.
116 \o Printing system improvements, including the QPrinterInfo, QPrintPreviewWidget
117 and QPrintPreviewDialog classes.
118 \o Support for \l{Windows CE - Introduction to using Qt}{Qt for Windows CE} as
119 a mainstream Qt platform.
120 \o Improvements in performance of Qt for Embedded Linux and extended support for
121 display hardware.
122 \endlist
123
124 In Qt 4.3:
125 \list
126 \o Support for different \l{The Qt 4 Main Window Classes}{main window paradigms and styles},
127 such as those found in Visual Studio or KDevelop.
128 \o The \l{QtScript} module, providing support for application scripting with ECMAScript.
129 \o Improved graphics features, including an experimental Direct3D paint engine
130 and improved provision for hardware accelerated rendering with OpenGL, and
131 support for OpenGL ES in Qt for Embedded Linux.
132 \o \l{QSvgGenerator}{Scalable Vector Graphics (SVG) export}, allowing SVG drawings to
133 be created using the standard QPainter API.
134 \o Support for arbitrary matrix transformations and set operations on painter paths.
135 \o Native look and feel on Windows Vista; improved look and feel on Mac OS X.
136 \o An improved \l{QMdiArea}{Multiple Document Interface (MDI)} implementation.
137 \o Continuous improvements to \QD, including support for
138 \l{Qt Designer's Widget Editing Mode#The Property Editor}{dynamic properties}.
139 \o Support for Secure Socket Layer (SSL) communications via the QSslSocket class.
140 \o Support for XML Localization Interchange File Format (XLIFF) files in \QL.
141 \o A new font subsystem for Qt for Embedded Linux.
142 \endlist
143
144 In Qt 4.2:
145 \list
146 \o The \l{Graphics View} framework for producing interactive graphics.
147 \o \l{Desktop Integration}{Desktop integration} facilities for applications.
148 \o \l{Qt Style Sheets} enable easy, yet powerful customization of
149 user interfaces.
150 \o Support for the \l{intro-to-dbus.html}{D-Bus} Inter-Process Communication (IPC) and Remote Procedure Calling (RPC) mechanism.
151 \o An \l{Undo Framework}{Undo framework} based on the
152 \l{Books about GUI Design#Design Patterns}{Command pattern}.
153 \o Support for model-based \l{QCompleter}{text completion} in standard and
154 custom widgets.
155 \o New widgets and GUI features, such as QCalendarWidget and
156 QGLFramebufferObject.
157 \o Classes to provide higher level application infrastructure, such as
158 QFileSystemWatcher and QDataWidgetMapper.
159 \endlist
160
161 In Qt 4.1:
162 \list
163 \o Integrated support for rendering
164 \l{The Arthur Paint System#SVG Rendering Support}{Scalable Vector Graphics}
165 (SVG) drawings and animations.
166 \o Support for
167 \l{QWidget#Transparency and Double Buffering}{child widget transparency}
168 on all platforms.
169 \o A Portable Document Format (PDF) backend for Qt's printing system.
170 \o A \l{QTestLib Manual}{unit testing framework} for Qt applications and
171 libraries.
172 \o Modules for \l{QtDesigner}{extending \QD} and
173 \l{QtUiTools}{dynamic user interface building}.
174 \o New \l{Proxy Models}{proxy models} to enable view-specific sorting and
175 filtering of data displayed using item views.
176 \o Support for \l{Installing Qt on Mac OS X}{universal binaries} on Mac OS X.
177 \o Additional features for developers using \l{QtOpenGL}{OpenGL}, such as
178 support for pixel and sample buffers.
179 \o A flexible \l{QSyntaxHighlighter}{syntax highlighting class} based on the
180 \l{Scribe} rich text framework.
181 \o Support for \l{QNetworkProxy}{network proxy} servers using the SOCKS5
182 protocol.
183 \o Support for OLE verbs and MIME data handling in \l{ActiveQt}.
184 \endlist
185
186 For more information about improvements in each Qt release, see
187 the \l{http://qt.nokia.com/developer/changes/}
188 {detailed lists of changes}.
189
190 \section1 Significant Improvements
191
192 The following modules have been significantly improved for Qt 4:
193
194 \list
195 \o A fully cross-platform \l{accessibility}
196 module, with support for the emerging SP-API Unix standard in
197 addition to Microsoft and Mac Accessibility.
198 \o The \l{qt4-sql.html}{SQL module}, which is now based on the
199 Interview model/view framework.
200 \o The \l{qt4-network.html}{network module}, with better support
201 for UDP and synchronous sockets.
202 \o The \l{qt4-styles.html}{style API}, which is now decoupled from
203 the widgets, meaning that you can draw any user interface element on
204 any device (widget, pixmap, etc.).
205 \o Enhanced \l{qt4-threads.html}{thread support}, with signal-slot
206 connections across threads and per-thread event loops.
207 \o A new \l{resource system} for embedding images
208 and other resource files into the application executable.
209 \endlist
210
211 \section1 Build System
212
213 Unlike previous Qt releases, Qt 4 is a collection of smaller
214 libraries:
215
216 \table
217 \header \o Library \o Description
218 \row \o \l{QtCore} \o Core non-GUI functionality
219 \row \o \l{QtGui} \o Core GUI functionality
220 \row \o \l{QtNetwork} \o Network module
221 \row \o \l{QtOpenGL} \o OpenGL module
222 \row \o \l{QtSql} \o SQL module
223 \row \o \l{QtSvg} \o SVG rendering classes
224 \row \o \l{QtXml} \o XML module
225 \row \o \l{Qt3Support} \o Qt 3 support classes
226 \row \o \l{QAxContainer} \o ActiveQt client extension
227 \row \o \l{QAxServer} \o ActiveQt server extension
228 \row \o \l{QtAssistant} \o Classes for launching Qt Assistant
229 \row \o \l{QtDesigner} \o Classes for extending and embedding Qt Designer
230 \row \o \l{QtUiTools} \o Classes for dynamic GUI generation
231 \row \o \l{QtTest} \o Tool classes for unit testing
232 \endtable
233
234 QtCore contains tool classes like QString, QList, and QFile, as
235 well as kernel classes like QObject and QTimer. The QApplication
236 class has been refactored so that it can be used in non-GUI
237 applications. It is split into QCoreApplication (in \l QtCore)
238 and QApplication (in \l QtGui).
239
240 This split makes it possible to develop server applications using Qt
241 without linking in any unnecessary GUI-related code and without
242 requiring GUI-related system libraries to be present on the target
243 machine (e.g. Xlib on X11, Carbon on Mac OS X).
244
245 If you use qmake to generate your makefiles, qmake will by default
246 link your application against QtCore and QtGui. To remove the
247 dependency upon QtGui, add the line
248
249 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 0
250
251 to your .pro file. To enable the other libraries, add the line
252
253 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 1
254
255 Another change to the build system is that moc now understands
256 preprocessor directives. qmake automatically passes the defines set
257 for your project (using "DEFINES +=") on to moc, which has its own
258 built-in C++ preprocessor.
259
260 To compile code that uses UI files, you will also need this line in
261 the .pro file:
262
263 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 2
264
265 \section1 Include Syntax
266
267 The syntax for including Qt class definitions has become
268
269 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 3
270
271 For example:
272
273 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 4
274
275 This is guaranteed to work for any public Qt class. The old syntax,
276
277 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 5
278
279 still works, but we encourage you to switch to the new syntax.
280
281 If you attempt to include a header file from a library that isn't
282 linked against the application, this will result in a
283 compile-time warning (e.g., "QSqlQuery: No such file or
284 directory"). You can remedy to this problem either by removing
285 the offending include or by specifying the missing library in the
286 QT entry of your \c .pro file (see \l{Build System} above).
287
288 To include the definitions for all the classes in a library, simply
289 specify the name of that library. For example:
290
291 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 6
292
293 \section1 Namespaces
294
295 Qt 2 introduced a class called Qt for global-like constants
296 (e.g., \c{Qt::yellow}). The C++ namespace construct was not used
297 because not all compilers understood it when it was released.
298
299 With Qt 4, the Qt class has become the Qt namespace. If you want
300 to access a constant that is part of the Qt namespace, prefix it
301 with \c Qt:: (e.g., \c{Qt::yellow}), or add the directive
302
303 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 7
304
305 at the top of your source files, after your \c #include
306 directives. If you use the \c{using namespace} syntax you don't
307 need the prefix (e.g., \c yellow is sufficient).
308
309 When porting Qt 3 applications, you may run into some source
310 compatibility problems with some of these symbols. For example,
311 in Qt 3, it was legal to write \c QWidget::yellow instead of \c
312 Qt::yellow, because QWidget inherited from Qt. This won't work in
313 Qt 4; you must write \c Qt::yellow or add the "using namespace"
314 directive and drop the \c Qt:: prefix.
315
316 The \l{qt3to4 - The Qt 3 to 4 Porting Tool}{qt3to4} porting tool
317 automates this conversion.
318
319 \section1 QObject/QWidget Constructors
320
321 In Qt 4 we have tried to simplify the constructors of QObject/QWidget
322 subclasses. This makes subclassing easier, at the same time as it
323 helps make the Qt library more efficient.
324
325 Constructors no longer take a "const char *name" parameter. If
326 you want to specify a name for a QObject, you must call
327 QObject::setObjectName() after construction. The object name is
328 now a QString. The reasons for this change are:
329
330 \list
331 \o Code that used it looked confusing, for example:
332
333 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 8
334
335 \c label1 is a QLabel that displays the text "Hello"; \c
336 label2 is a QLabel with no text, with the object name
337 "Hello".
338
339 \o From surveys we did, most users didn't use the name, although
340 they blindly followed Qt's convention and provided a "const
341 char *name" in their subclasses's constructors. For example:
342
343 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 9
344
345 \o The name parameter was in Qt since version 1, and it always
346 was documented as: "It is not very useful in the current
347 version of Qt, but it will become increasingly important in
348 the future." Ten years later, it still hasn't fulfilled its
349 promise.
350 \endlist
351
352 QWidget's \c WFlags data type has been split in two:
353 Qt::WindowFlags specifies low-level window flags (the type of
354 window and the frame style), whereas Qt::WidgetAttribute
355 specifies various higher-level attributes about the widget (e.g.,
356 WA_StaticContents). Widget attributes can be set at any time
357 using QWidget::setAttribute(); low-level window flags can be
358 passed to the QWidget constructor or set later using
359 QWidget::setParent(). As a consequence, the constructors of most
360 QWidget subclasses don't need to provide a \c WFlags parameter.
361
362 The \e parent parameter of all QObject classes in Qt defaults to
363 a 0 pointer, as it used to do in Qt 1. This enables a style of
364 programming where widgets are created without parents and then
365 inserted in a layout, at which point the layout automatically
366 reparents them.
367
368 \section1 Dynamic Casts
369
370 Qt 4 provides a qobject_cast<>() function that performs a dynamic cast
371 based on the meta-information generated by moc for QObject
372 subclasses. Unlike the standard C++ dynamic_cast<>() construct,
373 qobject_cast<>() works even when RTTI is disabled, and it works correctly
374 across DLL boundaries.
375
376 Here's the Qt 3 idiom to cast a type to a subtype:
377
378 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 10
379
380 The Qt 4 idiom is both cleaner and safer, because typos will always
381 result in compiler errors:
382
383 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 11
384
385 \section1 QPointer<T>
386
387 The QPointer<T> class provides a pointer to type T (where T inherits
388 from QObject) that is automatically set to 0 when the referenced
389 object is destroyed. Guarded pointers are useful whenever you want to
390 store a pointer to an object you do not own.
391
392 Example:
393
394 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 12
395
396 QPointer<T> is more or less the same as the old QGuardedPtr<T> class,
397 except that it is now implemented in a much more lightweight manner
398 than before. The cost of one QPointer<T> object is now approximately
399 the same as that of a signal--slot connection.
400
401 \section1 Paint Events
402
403 Qt 4 supports double buffering transparently on all platforms. This
404 feature can be turned off on a per-widget basis by calling
405 QWidget::setAttribute(Qt::WA_PaintOnScreen).
406
407 A consequence of this is that all painting must now be done from the
408 paintEvent() function. This is also required by the HIView API on Mac
409 OS X. In practice, this is seldom a problem, since you can call
410 update() from anywhere in your code to create a paint event, with the
411 region to update as the argument.
412
413 To help porting, QWidget supports a Qt::WA_PaintOutsidePaintEvent
414 attribute that can be set to make it possible to paint outside
415 \l{QWidget::paintEvent()}{paintEvent()} on Windows and X11.
416
417 \section1 Qt 3 Support Layer
418
419 Qt 4 provides an extension library that applications based on Qt 3,
420 called Qt3Support, that Qt applications can link against. This allows
421 for more compatibility than ever before, without bloating Qt.
422
423 \list
424 \o Classes that have been replaced by a different class with the
425 same name, such as QListView, and classes that no longer exist in Qt 4
426 are available with a \c 3 in their name (e.g., Q3ListView, Q3Accel).
427
428 \o Other classes provide compatibility functions. Most of these are
429 implemented inline, so that they don't bloat the Qt libraries.
430 \endlist
431
432 To enable the Qt 3 support classes and functions, add the line
433
434 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 13
435
436 to your \c .pro file.
437
438 On Visual C++ 7 and GCC 3.2+, using compatibility functions often results
439 in a compiler warning (e.g., "'find' is deprecated"). If you want to turn
440 off that warning, add the line
441
442 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 14
443
444 to your \c .pro file.
445
446 If you want to use compatibility functions but don't want to link
447 against the Qt3Support library, add the line
448
449 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 15
450
451 or
452
453 \snippet doc/src/snippets/code/doc_src_qt4-intro.qdoc 16
454
455 to your \c .pro file, depending on whether you want compatibility
456 function calls to generate compiler warnings or not.
457*/
458
459/*!
460 \page qt4-6-intro.html
461 \title What's New in Qt 4.6
462
463 Qt 4.6 provides many improvements and enhancements over the
464 previous releases in the Qt 4 series. This document covers the
465 most important features in this release, separated by category.
466
467\omit
468 A comprehensive list of changes between Qt 4.5 and Qt 4.6 is
469 included in the \c changes-4.6.0 file
470 \l{http://qt.nokia.com/developer/changes/changes-4.6.0}{available
471 online}. A \l{Known Issues in 4.6.2}{list of known issues}
472 for this release is also available.
473
474 Changes between this release and the previous release are provided
475 in the \c{changes-4.6.2} file (also
476 \l{http://qt.nokia.com/developer/changes/changes-4.6.2}{available online}).
477\endomit
478
479 A list of other Qt 4 features can be found on the \bold{\l{What's
480 New in Qt 4}} page.
481
482 \bold{Highlights}
483
484 \tableofcontents
485
486 \section1 Support for Symbian
487
488 Qt 4.6 is the first release to include support for the Symbian
489 platform, with integration into the S60 framework. The port to
490 Symbian and S60 provides all functionality required to develop
491 rich end-user applications for devices running S60 3.1 and
492 later.
493
494 See the \l{The Symbian platform - Introduction to Qt} for more information.
495
496 \section1 Animation Framework
497
498 The animation framework helps build highly animated,
499 high-performance GUIs without the hassle of managing complex
500 structures, timers, and easing curves, not to mention the large
501 state graphs that all animated GUIs tend to be full of.
502
503 The framework makes it easy to animate \l{QObject}s, including
504 QWidgets, by allowing Qt properties to be animated. It also allows
505 creating custom animations and interpolation functions. Graphics
506 views are not left out; one can animate \l{QGraphicsWidget}s and
507 new \l{QGraphicsObject}s which inherit from QGraphicsItem
508 (and thereby enable properties).
509
510 Animations are controlled using easing curves and can be grouped
511 together. This enables animations of arbitrary complexity.
512
513 The API is easy to grasp with functions such as start(), stop(),
514 pause(), and currentTime(). Here is an image from one of the
515 examples that come with the framework:
516
517 \image whatsnewanimatedtiles.png
518
519 The animation framework also plugs into the new Qt Statemachine by
520 allowing an animation to be played when transitions are triggered.
521 The state machine framework is introduced in 4.6 and is described
522 below.
523
524 See \l{The Animation Framework} documentation for more information.
525
526 \section1 State Machine Framework
527
528 The state machine framework provides a robust state chart
529 implementation based on Harel statecharts and SCXML. Qt's API lets
530 you construct such state graphs and execute them. The key benefits
531 of a state machine are:
532
533 \list
534 \o Simplify complex application semantics.
535 \o Use of states to reduce code bloat.
536 \o Use states to improve maintainability.
537 \o Makes event-driven programming robust and more
538 reusable.
539 \endlist
540
541 It is especially the last item here that makes using a state
542 machine worthwhile. A key characteristic of event-driven systems
543 (such as Qt applications) is that behavior often depends not only
544 on the last or current event, but also the events that preceded