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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qt4-intro.qdoc -->
<title>Qt 4.8: What's New in Qt 4</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="content">
<a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
</div>
<div class="breadcrumb toolblock">
<ul>
<li class="first"><a href="index.html">Home</a></li>
<!-- Breadcrumbs go here -->
<li>What's New in Qt 4</li>
</ul>
</div>
</div>
<div class="content mainContent">
<link rel="next" href="qt4-tulip.html" />
<link rel="start" href="index.html" />
<p class="naviNextPrevious headerNavi">
<a class="nextPage" href="qt4-tulip.html">The Tulip Container Classes</a>
</p><p/>
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#new-technologies-in-qt-4">New Technologies in Qt 4</a></li>
<li class="level1"><a href="#recent-additions-to-qt-4">Recent Additions to Qt 4</a></li>
<li class="level1"><a href="#significant-improvements">Significant Improvements</a></li>
<li class="level1"><a href="#build-system">Build System</a></li>
<li class="level1"><a href="#include-syntax">Include Syntax</a></li>
<li class="level1"><a href="#namespaces">Namespaces</a></li>
<li class="level1"><a href="#qobject-qwidget-constructors">QObject/QWidget Constructors</a></li>
<li class="level1"><a href="#dynamic-casts">Dynamic Casts</a></li>
<li class="level1"><a href="#qpointer-t">QPointer<T></a></li>
<li class="level1"><a href="#paint-events">Paint Events</a></li>
<li class="level1"><a href="#qt-3-support-layer">Qt 3 Support Layer</a></li>
</ul>
</div>
<h1 class="title">What's New in Qt 4</h1>
<span class="subtitle"></span>
<!-- $$$qt4-intro.html-description -->
<div class="descr"> <a name="details"></a>
<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>
<a name="new-technologies-in-qt-4"></a>
<h2>New Technologies in Qt 4</h2>
<p>Qt 4 introduces the following core technologies:</p>
<ul>
<li><a href="qt4-tulip.html">Tulip</a>, a new set of template container classes.</li>
<li><a href="qt4-interview.html">Interview</a>, a model/view architecture for item views.</li>
<li><a href="qt4-arthur.html">Arthur</a>, the Qt 4 painting framework.</li>
<li><a href="qt4-scribe.html">Scribe</a>, the Unicode text renderer with a public API for performing low-level text layout.</li>
<li><a href="qt4-mainwindow.html">Mainwindow</a>, a modern action-based mainwindow, toolbar, menu, and docking architecture.</li>
<li>The new <a href="qt4-designer.html"><i>Qt Designer</i></a> user interface design tool.</li>
</ul>
<a name="recent-additions-to-qt-4"></a>
<h2>Recent Additions to Qt 4</h2>
<p>The following features have been added to Qt since the first release of Qt 4.</p>
<p>In Qt 4.8:</p>
<ul>
<li><a href="qtquick.html">Qt Quick</a> 1.1 offers changes to the <a href="qdeclarativeelements.html">QML Elements</a> and performance upgrades</li>
</ul>
<p>In Qt 4.7:</p>
<ul>
<li>Declarative UI Development with <a href="qtquick.html">Qt Quick</a>, technologies for creating fluid, dynamic user interfaces.</li>
<li>Support for <a href="bearer-management.html">network bearer management</a>, enabling features such as control over network interfaces and support for roaming between networks.</li>
<li>Feature and performance improvements in <a href="qtwebkit.html">QtWebKit</a>, including a new tiled backing store, control over scroll bars used in frames and framesets, accelerated compositing and <a href="qtwebkit-bridge.html">support for hybrid development</a>.</li>
<li>General performance improvements, including the use of "alien widgets" on Mac OS X, the <a href="qstatictext.html">QStaticText</a> class for optimized text rendering, a new <a href="qpainter.html#drawPixmapFragments">API for rendering pixmap fragments</a> and an updated version of the <a href="3rdparty.html#javascriptcore">JavaScriptCore</a> engine for the <a href="qtscript.html">QtScript</a> module with improved performance.</li>
</ul>
<p>In Qt 4.6:</p>
<ul>
<li>Support for <a href="symbian-with-qt-introduction.html">the Symbian Platform</a> as a mainstream Qt platform, with integration into the S60 framework.</li>
<li>The <a href="animation-overview.html">animation framework</a> allows animations to be created using both widgets and graphics items.</li>
<li>The <a href="statemachine-api.html">state machine framework</a> provides a robust state chart implementation based on Harel statecharts and SCXML.</li>
<li>Support for <a href="qtouchevent.html">touch input</a> and <a href="gestures-overview.html">gestures</a> enable developers to create intuitive user interfaces for touch-based devices.</li>
<li>A <a href="qwebelement.html">DOM access API</a> for <a href="qtwebkit.html">QtWebKit</a> provides a cleaner and safer way to access elements and structures of Web pages without the use of JavaScript.</li>
<li>A collection of performance improvements, covering <a href="qgraphicsview.html">QGraphicsView</a>, <a href="qpixmapcache.html">QPixmapCache</a>, <a href="qnetworkaccessmanager.html">QNetworkAccessManager</a>, <a href="qcontiguouscache.html">QContiguousCache</a> class, hardware-accelerated rendering support through <a href="openvg.html">OpenVG</a>, and the removal of Win9x support.</li>
<li>A collection of <a href="qgraphicseffect.html">graphics effects</a> make it easy to apply and simple effects to graphics items and combine them to produce more complex effects.</li>
<li>Support for XML schema validation in the <a href="qtxmlpatterns.html">QtXmlPatterns</a> module covering large parts of version 1.0 of the specification.</li>
<li>Qt3D enablers, including math primitives for <a href="qmatrix4x4.html">matrix multiplication</a>, <a href="qvector3d.html">vectors</a>, <a href="qquaternion.html">quaternions</a> (client-side), and an API for <a href="qglshader.html">vertex and fragment shaders</a>, GLSL/ES.</li>
<li><a href="qtmultimedia.html">Multimedia services</a> providing low-level access to the system's audio system.</li>
</ul>
<p>In Qt 4.5:</p>
<ul>
<li>The WebKit browser engine included with Qt has been upgraded to the latest upstream (trunk) version of WebKit, bringing the latest features and improvements to Qt applications.</li>
<li>Qt for Mac OS X has been substantially rewritten to use Apple's Cocoa API, enabling Qt applications to be deployed on 64-bit Macintosh hardware.</li>
<li>The <a href="qtxmlpatterns.html">QtXmlPatterns</a> module has been extended to cover XSLT, a transformation language for XML documents.</li>
<li>Qt Script introduced its debugger, providing error reporting for scripts, and to let users track down bugs in their own scripts.</li>
<li>Qt 4.5 includes support for writing rich text documents as OpenDocument files via the newly-introduced <a href="qtextdocumentwriter.html">QTextDocumentWriter</a> class.</li>
<li>Qt Linguist can load and edit multiple translation files simultaneously.</li>
<li>Support for ARGB top-level widgets (i.e., translucent windows).</li>
</ul>
<p>In Qt 4.4:</p>
<ul>
<li><a href="qtwebkit.html">Qt WebKit integration</a>, making it possible for developers to use a fully-featured Web browser to display documents and access online services.</li>
<li>A multimedia API provided by the <a href="phonon-overview.html#phonon-overview">Phonon Multimedia Framework</a>.</li>
<li><a href="qtxmlpatterns.html">XQuery and XPath</a> support, providing facilities for XML processing beyond that supported by the <a href="qtxml.html">QtXml</a> module.</li>
<li>Support for embedded widgets in <a href="graphicsview.html#graphics-view">Graphics View</a> scenes.</li>
<li>The <a href="threads.html">QtConcurrent framework</a> for concurrent programming using Qt paradigms and threading features.</li>
<li>An <a href="qthelp.html">improved help system</a> that can be used in conjunction with Qt Assistant or as an independent help resource manager.</li>
<li>Printing system improvements, including the <a href="qprinterinfo.html">QPrinterInfo</a>, <a href="qprintpreviewwidget.html">QPrintPreviewWidget</a> and <a href="qprintpreviewdialog.html">QPrintPreviewDialog</a> classes.</li>
<li>Support for <a href="wince-with-qt-introduction.html">Qt for Windows CE</a> as a mainstream Qt platform.</li>
<li>Improvements in performance of Qt for Embedded Linux and extended support for display hardware.</li>
</ul>
<p>In Qt 4.3:</p>
<ul>
<li>Support for different <a href="qt4-mainwindow.html">main window paradigms and styles</a>, such as those found in Visual Studio or KDevelop.</li>
<li>The <a href="qtscript.html">QtScript</a> module, providing support for application scripting with ECMAScript.</li>
<li>Improved graphics features, including an experimental Direct3D paint engine and improved provision for hardware accelerated rendering with OpenGL, and support for OpenGL ES in Qt for Embedded Linux.</li>
<li><a href="qsvggenerator.html">Scalable Vector Graphics (SVG) export</a>, allowing SVG drawings to be created using the standard <a href="qpainter.html">QPainter</a> API.</li>
<li>Support for arbitrary matrix transformations and set operations on painter paths.</li>
<li>Native look and feel on Windows Vista; improved look and feel on Mac OS X.</li>
<li>An improved <a href="qmdiarea.html">Multiple Document Interface (MDI)</a> implementation.</li>
<li>Continuous improvements to <i>Qt Designer</i>, including support for <a href="designer-widget-mode.html#the-property-editor">dynamic properties</a>.</li>
<li>Support for Secure Socket Layer (SSL) communications via the <a href="qsslsocket.html">QSslSocket</a> class.</li>
<li>Support for XML Localization Interchange File Format (XLIFF) files in <i>Qt Linguist</i>.</li>
<li>A new font subsystem for Qt for Embedded Linux.</li>
</ul>
<p>In Qt 4.2:</p>
<ul>
<li>The <a href="graphicsview.html#graphics-view">Graphics View</a> framework for producing interactive graphics.</li>
<li><a href="desktop-integration.html">Desktop integration</a> facilities for applications.</li>
<li><a href="stylesheet.html">Qt Style Sheets</a> enable easy, yet powerful customization of user interfaces.</li>
<li>Support for the <a href="intro-to-dbus.html">D-Bus</a> Inter-Process Communication (IPC) and Remote Procedure Calling (RPC) mechanism.</li>
<li>An <a href="demos-undo.html">Undo framework</a> based on the <a href="guibooks.html#design-patterns">Command pattern</a>.</li>
<li>Support for model-based <a href="qcompleter.html">text completion</a> in standard and custom widgets.</li>
<li>New widgets and GUI features, such as <a href="qcalendarwidget.html">QCalendarWidget</a> and <a href="qglframebufferobject.html">QGLFramebufferObject</a>.</li>
<li>Classes to provide higher level application infrastructure, such as <a href="qfilesystemwatcher.html">QFileSystemWatcher</a> and <a href="qdatawidgetmapper.html">QDataWidgetMapper</a>.</li>
</ul>
<p>In Qt 4.1:</p>
<ul>
<li>Integrated support for rendering <a href="qt4-arthur.html#svg-rendering-support">Scalable Vector Graphics</a> (SVG) drawings and animations.</li>
<li>Support for <a href="qwidget.html#transparency-and-double-buffering">child widget transparency</a> on all platforms.</li>
<li>A Portable Document Format (PDF) backend for Qt's printing system.</li>
<li>A <a href="qtestlib-manual.html">unit testing framework</a> for Qt applications and libraries.</li>
<li>Modules for <a href="qtdesigner.html">extending <i>Qt Designer</i></a> and <a href="qtuitools.html">dynamic user interface building</a>.</li>
<li>New <a href="model-view-programming.html#proxy-models">proxy models</a> to enable view-specific sorting and filtering of data displayed using item views.</li>
<li>Support for <a href="install-mac.html">universal binaries</a> on Mac OS X.</li>
<li>Additional features for developers using <a href="qtopengl.html">OpenGL</a>, such as support for pixel and sample buffers.</li>
<li>A flexible <a href="qsyntaxhighlighter.html">syntax highlighting class</a> based on the <a href="qt4-scribe.html#scribe">Scribe</a> rich text framework.</li>
<li>Support for <a href="qnetworkproxy.html">network proxy</a> servers using the SOCKS5 protocol.</li>
<li>Support for OLE verbs and MIME data handling in <a href="activeqt.html#activeqt">ActiveQt</a>.</li>
</ul>
<p>For more information about improvements in each Qt release, see the <a href="http://qt.nokia.com/developer/changes/">detailed lists of changes</a>.</p>
<a name="significant-improvements"></a>
<h2>Significant Improvements</h2>
<p>The following modules have been significantly improved for Qt 4:</p>
<ul>
<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>
<li>The <a href="qt4-sql.html">SQL module</a>, which is now based on the Interview model/view framework.</li>
<li>The <a href="qt4-network.html">network module</a>, with better support for UDP and synchronous sockets.</li>
<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>
<li>Enhanced <a href="qt4-threads.html">thread support</a>, with signal-slot connections across threads and per-thread event loops.</li>
<li>A new <a href="resources.html#resource-system">resource system</a> for embedding images and other resource files into the application executable.</li>
</ul>
<a name="build-system"></a>
<h2>Build System</h2>
<p>Unlike previous Qt releases, Qt 4 is a collection of smaller libraries. A complete list of libraries in the current release of Qt can be found on the <a href="modules.html">All Modules</a> page. The following table describes the initial set of libraries released with Qt 4.</p>
<table class="generic">
<thead><tr class="qt-style"><th >Library</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td ><a href="qtcore.html">QtCore</a></td><td >Core non-GUI functionality</td></tr>
<tr valign="top" class="even"><td ><a href="qtgui.html">QtGui</a></td><td >Core GUI functionality</td></tr>
<tr valign="top" class="odd"><td ><a href="qtnetwork.html">QtNetwork</a></td><td >Network module</td></tr>
<tr valign="top" class="even"><td ><a href="qtopengl.html">QtOpenGL</a></td><td >OpenGL module</td></tr>
<tr valign="top" class="odd"><td ><a href="qtsql.html">QtSql</a></td><td >SQL module</td></tr>
<tr valign="top" class="even"><td ><a href="qtsvg.html">QtSvg</a></td><td >SVG rendering classes</td></tr>
<tr valign="top" class="odd"><td ><a href="qtxml.html">QtXml</a></td><td >XML module</td></tr>
<tr valign="top" class="even"><td ><a href="qt3support.html">Qt3Support</a></td><td >Qt 3 support classes</td></tr>
<tr valign="top" class="odd"><td ><a href="qaxcontainer.html">QAxContainer</a></td><td ><a href="activeqt.html#activeqt">ActiveQt</a> client extension</td></tr>
<tr valign="top" class="even"><td ><a href="qaxserver.html">QAxServer</a></td><td ><a href="activeqt.html#activeqt">ActiveQt</a> server extension</td></tr>
<tr valign="top" class="odd"><td ><a href="qthelp.html">QtHelp</a></td><td >Classes for integrating online documentation</td></tr>
<tr valign="top" class="even"><td ><a href="qtdesigner.html">QtDesigner</a></td><td >Classes for extending and embedding Qt Designer</td></tr>
<tr valign="top" class="odd"><td ><a href="qtuitools.html">QtUiTools</a></td><td >Classes for dynamic GUI generation</td></tr>
<tr valign="top" class="even"><td ><a href="qttest.html">QtTest</a></td><td >Tool classes for unit testing</td></tr>
</table>
<p><a href="qtcore.html">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</a>) and <a href="qapplication.html">QApplication</a> (in <a href="qtgui.html">QtGui</a>).</p>
<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 X11, Carbon on Mac OS X).</p>
<p>If you use qmake to generate your makefiles, qmake will by default link your application against <a href="qtcore.html">QtCore</a> and <a href="qtgui.html">QtGui</a>. To remove the dependency upon <a href="qtgui.html">QtGui</a>, add the line</p>
<pre class="cpp"> QT -= gui</pre>
<p>to your .pro file. To enable the other libraries, add the line</p>
<pre class="cpp"> QT += network opengl sql qt3support</pre>
<p>Another change to the build system is that moc now understands preprocessor directives. qmake automatically passes the defines set for your project (using "DEFINES +=") on to moc, which has its own built-in C++ preprocessor.</p>
<p>To compile code that uses UI files, you will also need this line in the .pro file:</p>
<pre class="cpp"> CONFIG += uic3</pre>
<a name="include-syntax"></a>
<h2>Include Syntax</h2>
<p>The syntax for including Qt class definitions has become</p>
<pre class="cpp"> <span class="preprocessor">#include <QClassName></span></pre>
<p>For example:</p>
<pre class="cpp"> <span class="preprocessor">#include <QString></span>
<span class="preprocessor">#include <QApplication></span>
<span class="preprocessor">#include <QSqlTableModel></span></pre>
<p>This is guaranteed to work for any public Qt class. The old syntax,</p>
<pre class="cpp"> <span class="preprocessor">#include <qclassname.h></span></pre>
<p>still works, but we encourage you to switch to the new syntax.</p>
<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., "<a href="qsqlquery.html">QSqlQuery</a>: No such file or directory"). 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>
<p>To include the definitions for all the classes in a library, simply specify the name of that library. For example:</p>
<pre class="cpp"> <span class="preprocessor">#include <QtCore></span></pre>
<a name="namespaces"></a>
<h2>Namespaces</h2>
<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>
<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>
<pre class="cpp"> <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="type"><a href="qt.html">Qt</a></span>;</pre>
<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>
<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 "using namespace" directive and drop the <tt>Qt::</tt> prefix.</p>
<p>The <a href="qt3to4.html">qt3to4</a> porting tool automates this conversion.</p>
<a name="qobject-qwidget-constructors"></a>
<h2>QObject/QWidget Constructors</h2>
<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>
<p>Constructors no longer take a "const char *name" 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>. The reasons for this change are:</p>
<ul>
<li>Code that used it looked confusing, for example:<pre class="cpp"> <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>label1 <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(<span class="string">"Hello"</span><span class="operator">,</span> <span class="keyword">this</span>);
<span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>label2 <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(<span class="keyword">this</span><span class="operator">,</span> <span class="string">"Hello"</span>);</pre>
<p><tt>label1</tt> is a <a href="qlabel.html">QLabel</a> that displays the text "Hello"; <tt>label2</tt> is a <a href="qlabel.html">QLabel</a> with no text, with the object name "Hello".</p>
</li>
<li>From surveys we did, most users didn't use the name, although they blindly followed Qt's convention and provided a "const char *name" in their subclasses's constructors. For example:<pre class="cpp"> MyWidget<span class="operator">::</span>MyWidget(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent<span class="operator">,</span> <span class="keyword">const</span> <span class="type">char</span> <span class="operator">*</span>name)
: <span class="type"><a href="qwidget.html">QWidget</a></span>(parent<span class="operator">,</span> name)
{
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
}</pre>
</li>
<li>The name parameter was in Qt since version 1, and it always was documented as: "It is not very useful in the current version of Qt, but it will become increasingly important in the future." Ten years later, it still hasn't fulfilled its promise.</li>
</ul>
<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>
<p>The <i>parent</i> parameter of all <a href="qobject.html">QObject</a> classes in Qt defaults to a 0 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>
<a name="dynamic-casts"></a>
<h2>Dynamic Casts</h2>
<p>Qt 4 provides a qobject_cast<>() 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><>() construct, qobject_cast<>() works even when RTTI is disabled, and it works correctly across DLL boundaries.</p>
<p>Here's the Qt 3 idiom to cast a type to a subtype:</p>
<pre class="cpp"> <span class="comment">// DEPRECATED</span>
<span class="keyword">if</span> (obj<span class="operator">-</span><span class="operator">></span>inherits(<span class="string">"QPushButton"</span>)) {
<span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>pushButton <span class="operator">=</span> (<span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>)obj;
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
}</pre>
<p>The Qt 4 idiom is both cleaner and safer, because typos will always result in compiler errors:</p>
<pre class="cpp"> <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>pushButton <span class="operator">=</span> qobject_cast<span class="operator"><</span><span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span><span class="operator">></span>(obj);
<span class="keyword">if</span> (pushButton) {
<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span>
}</pre>
<a name="qpointer-t"></a>
<h2>QPointer<T></h2>
<p>The <a href="qpointer.html">QPointer</a><T> 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>
<p>Example:</p>
<pre class="cpp"> <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>label <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
<span class="type"><a href="qpointer.html">QPointer</a></span><span class="operator"><</span><span class="type"><a href="qlabel.html">QLabel</a></span><span class="operator">></span> safeLabel <span class="operator">=</span> label;
safeLabel<span class="operator">-</span><span class="operator">></span>setText(<span class="string">"Hello world!"</span>);
<span class="keyword">delete</span> label;
<span class="comment">// safeLabel is now 0, whereas label is a dangling pointer</span></pre>
<p><a href="qpointer.html">QPointer</a><T> is more or less the same as the old QGuardedPtr<T> 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><T> object is now approximately the same as that of a signal--slot connection.</p>
<a name="paint-events"></a>
<h2>Paint Events</h2>
<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>
<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>
<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 X11.</p>
<a name="qt-3-support-layer"></a>
<h2>Qt 3 Support Layer</h2>
<p>Qt 4 provides an extension library that applications based on Qt 3, called <a href="qt3support.html">Qt3Support</a>, that Qt applications can link against. This allows for more compatibility than ever before, without bloating Qt.</p>
<ul>
<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" class="compat">Q3ListView</a>, <a href="q3accel.html" class="compat">Q3Accel</a>).</li>
<li>Other classes provide compatibility functions. Most of these are implemented inline, so that they don't bloat the Qt libraries.</li>
</ul>
<p>To enable the Qt 3 support classes and functions, add the line</p>
<pre class="cpp"> QT += qt3support</pre>
<p>to your <tt>.pro</tt> file.</p>
<p>On Visual C++ 7 and GCC 3.2+, using compatibility functions often results in a compiler warning (e.g., "'find' is deprecated"). If you want to turn off that warning, add the line</p>
<pre class="cpp"> DEFINES += QT3_SUPPORT</pre>
<p>to your <tt>.pro</tt> file.</p>
<p>If you want to use compatibility functions but don't want to link against the <a href="qt3support.html">Qt3Support</a> library, add the line</p>
<pre class="cpp"> DEFINES += QT3_SUPPORT_WARNINGS</pre>
<p>or</p>
<pre class="cpp"> DEFINES += QT3_SUPPORT</pre>
<p>to your <tt>.pro</tt> file, depending on whether you want compatibility function calls to generate compiler warnings or not.</p>
</div>
<!-- @@@qt4-intro.html -->
<p class="naviNextPrevious footerNavi">
<a class="nextPage" href="qt4-tulip.html">The Tulip Container Classes</a>
</p>
<div class="ft">
<span></span>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2012 Nokia Corporation and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.</p>
<br />
<p>
The documentation provided herein is licensed under the terms of the
<a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
License version 1.3</a> as published by the Free Software Foundation.</p>
<p>
Documentation sources may be obtained from <a href="http://www.qt-project.org">
www.qt-project.org</a>.</p>
<br />
<p>
Nokia, Qt and their respective logos are trademarks of Nokia Corporation
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. <a title="Privacy Policy"
href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>
|