Sophie

Sophie

distrib > * > 2009.0 > i586 > by-pkgid > a6711891ce757817bba854bf3f25205a > files > 2278

qtjambi-doc-4.3.3-3mdv2008.1.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /home/gvatteka/dev/qt-4.3/doc/src/qt4-intro.qdoc -->
<head>
  <title>What's New in Qt 4</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1 align="center">What's New in Qt 4<br /><small></small></h1>
<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>
<ul><li><a href="#new-technologies-in-qt-4">New Technologies in Qt 4</a></li>
<li><a href="#recent-additions-to-qt-4">Recent Additions to Qt 4</a></li>
<li><a href="#significant-improvements">Significant Improvements</a></li>
<li><a href="#build-system">Build System</a></li>
<li><a href="#include-syntax">Include Syntax</a></li>
<li><a href="#namespaces">Namespaces</a></li>
<li><a href="#qobject-qwidget-constructors">QObject/QWidget Constructors</a></li>
<li><a href="#dynamic-casts">Dynamic Casts</a></li>
<li><a href="#qpointer-t">QPointer&lt;T&gt;</a></li>
<li><a href="#paint-events">Paint Events</a></li>
<li><a href="#qt-3-support-layer">Qt 3 Support Layer</a></li>
</ul>
<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</tt></a>, a new set of template container classes.</li>
<li><a href="qt4-interview.html">Interview</tt></a>, a model/view architecture for item views.</li>
<li><a href="qt4-arthur.html">Arthur</tt></a>, the Qt 4 painting framework.</li>
<li><a href="qt4-scribe.html">Scribe</tt></a>, the Unicode text renderer with a public API for performing low-level text layout.</li>
<li><a href="qt4-mainwindow.html">Mainwindow</tt></a>, a modern action-based mainwindow, toolbar, menu, and docking architecture.</li>
<li>The new <a href="qt4-designer.html"><i>Qt Designer</tt></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.2:</p>
<ul>
<li>The <a href="graphicsview.html#graphics-view">Graphics View</tt></a> framework for producing interactive graphics.</li>
<li><a href="desktop-integration.html">Desktop integration</tt></a> facilities for applications.</li>
<li><a href="stylesheet.html">Qt Style Sheets</tt></a> enable easy, yet powerful customization of user interfaces.</li>
<li>Support for the <a href="intro-to-dbus.html">D-Bus</tt></a> Inter-Process Communication (IPC) and Remote Procedure Calling (RPC) mechanism.</li>
<li>An <a href="qundo.html#undo-framework">Undo framework</tt></a> based on the <a href="guibooks.html#design-patterns">Command pattern</tt></a>.</li>
<li>Support for model-based <a href="gui/QCompleter.html">text completion</tt></a> in standard and custom widgets.</li>
<li>New widgets and GUI features, such as <a href="gui/QCalendarWidget.html"><tt>QCalendarWidget</tt></a> and <a href="opengl/QGLFramebufferObject.html"><tt>QGLFramebufferObject</tt></a>.</li>
<li>Classes to provide higher level application infrastructure, such as <a href="core/QFileSystemWatcher.html"><tt>QFileSystemWatcher</tt></a> and <a href="gui/QDataWidgetMapper.html"><tt>QDataWidgetMapper</tt></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</tt></a> (SVG) drawings and animations.</li>
<li>Support for <a href="gui/QWidget.html#transparency-and-double-buffering">child widget transparency</tt></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</tt></a> for Qt applications and libraries.</li>
<li>Modules for extending </tt><i>Qt Designer</tt></i> and dynamic user interface building</tt>.</li>
<li>New <a href="model-view-proxy-models.html">proxy models</tt></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</tt></a> on Mac OS X.</li>
<li>Additional features for developers using OpenGL, such as support for pixel and sample buffers.</li>
<li>A flexible <a href="gui/QSyntaxHighlighter.html">syntax highlighting class</tt></a> based on the <a href="qt4-scribe.html#scribe">Scribe</tt></a> rich text framework.</li>
<li>Support for <a href="network/QNetworkProxy.html">network proxy</tt></a> servers using the SOCKS5 protocol.</li>
<li>Support for OLE verbs and MIME data handling in <a href="activeqt.html#activeqt"><tt>ActiveQt</tt></a>.</li>
</ul>
<p>For more information about improvements in the current release, see the <a href="http://www.trolltech.com/developer/notes/changes/changes-4.1.4/">detailed list of changes</tt></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="accessible.html">accessibility</tt></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</tt></a>, which is now based on the Interview model/view framework.</li>
<li>The <a href="qt4-network.html">network module</tt></a>, with better support for UDP and synchronous sockets.</li>
<li>The <a href="qt4-styles.html">style API</tt></a>, which is now decoupled from the widgets, meaning that you can draw any user interface element on any device (widget, pixmap, etc.)&#x2e;</li>
<li>Enhanced <a href="qt4-threads.html">thread support</tt></a>, with signal-slot connections across threads and per-thread event loops.</li>
<li>A new <a href="resources.html#resource-system">resource system</tt></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:</p>
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
<thead><tr valign="top" class="qt-style"><th>Library</th><th>Description</th></tr></thead>
<tr valign="top" class="odd"><td><tt>QtCore</tt></td><td>Core non-GUI functionality</td></tr>
<tr valign="top" class="even"><td><tt>QtGui</tt></td><td>Core GUI functionality</td></tr>
<tr valign="top" class="odd"><td><tt>QtNetwork</tt></td><td>Network module</td></tr>
<tr valign="top" class="even"><td><tt>QtOpenGL</tt></td><td>OpenGL module</td></tr>
<tr valign="top" class="odd"><td><tt>QtSql</tt></td><td>SQL module</td></tr>
<tr valign="top" class="even"><td><tt>QtSvg</tt></td><td>SVG rendering classes</td></tr>
<tr valign="top" class="odd"><td><tt>QtXml</tt></td><td>XML module</td></tr>
<tr valign="top" class="even"><td><tt>Qt3Support</tt></td><td>Qt 3 support classes</td></tr>
<tr valign="top" class="odd"><td><tt>QAxContainer</tt></td><td><a href="activeqt.html#activeqt"><tt>ActiveQt</tt></a> client extension</td></tr>
<tr valign="top" class="even"><td><tt>QAxServer</tt></td><td><a href="activeqt.html#activeqt"><tt>ActiveQt</tt></a> server extension</td></tr>
<tr valign="top" class="odd"><td><tt>QtAssistant</tt></td><td>Classes for launching Qt Assistant</td></tr>
<tr valign="top" class="even"><td><tt>QtDesigner</tt></td><td>Classes for extending and embedding Qt Designer</td></tr>
<tr valign="top" class="odd"><td><tt>QtUiTools</tt></td><td>Classes for dynamic GUI generation</td></tr>
<tr valign="top" class="even"><td><tt>QtTest</tt></td><td>Tool classes for unit testing</td></tr>
</table></p>
<p>QtCore contains tool classes like <a href="porting4.html#qstring"><tt>QString</tt></a>, QList, and <a href="core/QFile.html"><tt>QFile</tt></a>, as well as kernel classes like <a href="core/QObject.html"><tt>QObject</tt></a> and <a href="core/QTimer.html"><tt>QTimer</tt></a>. The <a href="gui/QApplication.html"><tt>QApplication</tt></a> class has been refactored so that it can be used in non-GUI applications. It is split into <a href="core/QCoreApplication.html"><tt>QCoreApplication</tt></a> (in <tt>QtCore</tt>) and <a href="gui/QApplication.html"><tt>QApplication</tt></a> (in <tt>QtGui</tt>).</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&#x2e; 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 QtCore and QtGui. To remove the dependency upon QtGui, add the line</p>
<pre>    QT -= gui</pre>
<p>to your .pro file. To enable the other libraries, add the line</p>
<pre>    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 &quot;DEFINES +=&quot;) 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>    CONFIG += uic3</pre>
<a name="include-syntax"></a>
<h2>Include Syntax</h2>
<p>The syntax for including Qt class definitions has become</p>
<pre>    #include &lt;QClassName&gt;</pre>
<p>For example:</p>
<pre>    #include &lt;QString&gt;
    #include &lt;QApplication&gt;
    #include &lt;QSqlTableModel&gt;</pre>
<p>This is guaranteed to work for any public Qt class. The old syntax,</p>
<pre>    #include &lt;qclassname.h&gt;</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&#x2e;, &quot;<a href="sql/QSqlQuery.html"><tt>QSqlQuery</tt></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="qt4-intro.html#build-system">Build System</tt></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>    #include &lt;QtCore&gt;</pre>
<a name="namespaces"></a>
<h2>Namespaces</h2>
<p>Qt 2 introduced a class called Qt for global-like constants (e.g&#x2e;, <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&#x2e;, <tt>Qt::yellow</tt>), or add the directive</p>
<pre>    using namespace Qt;</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&#x2e;, <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="gui/QWidget.html"><tt>QWidget</tt></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>
<p>The <a href="qt3to4.html"><tt>qt3to4</tt></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="core/QObject.html"><tt>QObject</tt></a>/<a href="gui/QWidget.html"><tt>QWidget</tt></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 &quot;const char *name&quot; parameter. If you want to specify a name for a <a href="core/QObject.html"><tt>QObject</tt></a>, you must call QObject::setObjectName() after construction. The object name is now a <a href="porting4.html#qstring"><tt>QString</tt></a>. The reasons for this change are:</p>
<ul>
<li>Code that used it looked confusing, for example:<pre>    QLabel *label1 = new QLabel(&quot;Hello&quot;, this);
    QLabel *label2 = new QLabel(this, &quot;Hello&quot;);</pre>
<p><tt>label1</tt> is a <a href="gui/QLabel.html"><tt>QLabel</tt></a> that displays the text &quot;Hello&quot;; <tt>label2</tt> is a <a href="gui/QLabel.html"><tt>QLabel</tt></a> with no text, with the object name &quot;Hello&quot;.</p>
</li>
<li>From surveys we did, most users didn't use the name, although they blindly followed Qt's convention and provided a &quot;const char *name&quot; in their subclasses's constructors. For example:<pre>    MyWidget::MyWidget(QWidget *parent, const char *name)
        : QWidget(parent, name)
    {
        ...
    }</pre>
</li>
<li>The name parameter was in Qt since version 1, and it always was documented as: &quot;It is not very useful in the current version of Qt, but it will become increasingly important in the future.&quot; Ten years later, it still hasn't fulfilled its promise.</li>
</ul>
<p><a href="gui/QWidget.html"><tt>QWidget</tt></a>'s <tt>WFlags</tt> data type has been split in two: Qt::WindowFlags specifies low-level window flags (the type of window and the frame style), whereas Qt::WidgetAttribute specifies various higher-level attributes about the widget (e.g&#x2e;, WA_StaticContents). Widget attributes can be set at any time using QWidget::setAttribute(); low-level window flags can be passed to the <a href="gui/QWidget.html"><tt>QWidget</tt></a> constructor or set later using QWidget::setParent(). As a consequence, the constructors of most <a href="gui/QWidget.html"><tt>QWidget</tt></a> subclasses don't need to provide a <tt>WFlags</tt> parameter.</p>
<p>The <i>parent</i> parameter of all <a href="core/QObject.html"><tt>QObject</tt></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&lt;&gt;() function that performs a dynamic cast based on the meta-information generated by moc for <a href="core/QObject.html"><tt>QObject</tt></a> subclasses. Unlike the standard C++ <a href="qt4-intro.html#dynamic-casts"><tt>dynamic_cast</tt></a>&lt;&gt;() construct, qobject_cast&lt;&gt;() 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><span class="comment">    // DEPRECATED</span>
    if (obj-&gt;inherits(&quot;QPushButton&quot;)) {
        QPushButton *pushButton = (QPushButton *)obj;
        ...
    }</pre>
<p>The Qt 4 idiom is both cleaner and safer, because typos will always result in compiler errors:</p>
<pre>    QPushButton *pushButton = qobject_cast&lt;QPushButton *&gt;(obj);
    if (pushButton) {
        ...
    }</pre>
<a name="qpointer-t"></a>
<h2>QPointer&lt;T&gt;</h2>
<p>The QPointer&lt;T&gt; class provides a pointer to type T (where T inherits from <a href="core/QObject.html"><tt>QObject</tt></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>    QLabel *label = new QLabel;
    QPointer&lt;QLabel&gt; safeLabel = label;
    safeLabel-&gt;setText(&quot;Hello world!&quot;);
    delete label;
<span class="comment">    // safeLabel is now 0, whereas label is a dangling pointer</span></pre>
<p>QPointer&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 QPointer&lt;T&gt; 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(Qt::WA_PaintOnScreen).</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="gui/QWidget.html"><tt>QWidget</tt></a> supports a Qt::WA_PaintOutsidePaintEvent attribute that can be set to make it possible to paint outside paintEvent() 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 Qt3Support, 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="gui/QListView.html"><tt>QListView</tt></a>, and classes that no longer exist in Qt 4 are available with a <tt>3</tt> in their name (e.g&#x2e;, Q3ListView, Q3Accel).</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>    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&#x2e;, &quot;'find' is deprecated&quot;). If you want to turn off that warning, add the line</p>
<pre>    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 Qt3Support library, add the line</p>
<pre>    DEFINES += QT3_SUPPORT_WARNINGS</pre>
<p>or</p>
<pre>    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>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2007 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt Jambi </div></td>
</tr></table></div></address></body>
</html>