doc/src/porting/porting4-overview.qdoc
changeset 7 f7bc934e204c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the documentation of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 /*!
       
    43     \page porting4-overview.html
       
    44     \title Moving from Qt 3 to Qt 4
       
    45     \ingroup porting
       
    46     \brief Porting advice for authors of new and existing Qt 3 applications.
       
    47 
       
    48     This document describes which parts of Qt should be used when
       
    49     writing an application with Qt 3, so that it can be upgraded to
       
    50     use Qt 4 later with a minimum of effort. However, the advice may
       
    51     also be useful to developers who are porting existing applications
       
    52     from Qt 3 to Qt 4.
       
    53 
       
    54     For a detailed overview
       
    55     of the porting process for existing Qt 3 applications, see the
       
    56     \l{Porting to Qt 4} document.
       
    57 
       
    58     \tableofcontents
       
    59 
       
    60     Since Qt 4 provides important new functionality at the cost of
       
    61     some compatibility with Qt 3, it is useful for developers of
       
    62     Qt 3-based applications to learn how to take advantage of
       
    63     Qt 3's API now while preparing for future changes that will be
       
    64     needed when upgrading to Qt 4.
       
    65 
       
    66     Certain advanced Qt 3 features were moved to the Qt 3 support
       
    67     library (\l{Qt3Support}) in Qt 4.0, and have been gradually
       
    68     replaced in subsequent releases of Qt 4.
       
    69 
       
    70     Making Qt 3 applications as portable to Qt 4 as possible
       
    71     enables a smooth transition between versions of Qt in the
       
    72     long term, and allows for a stable development process
       
    73     throughout.
       
    74 
       
    75     \section1 Qt 3 Features to Avoid
       
    76 
       
    77     Although we are proud of the level of stability we have achieved
       
    78     with Qt, it is important to realise that, for Qt 4 to be a
       
    79     substantial improvement over Qt 3, certain features have
       
    80     been revised to make the framework more maintainable for us
       
    81     and more usable for developers. It is therefore useful to
       
    82     know which features of Qt 3 should be avoided to help save
       
    83     time during a later porting effort to Qt 4. Note that it is
       
    84     still possible to use many of the following classes and
       
    85     features through the use of the \l{Qt3Support} module.
       
    86 
       
    87     \section2 Painting Outside Paint Events
       
    88 
       
    89     In Qt 3, under certain circumstances, it was possible to use
       
    90     QPainter to draw on a given custom widget outside its
       
    91     \l{QWidget::}{paintEvent()} reimplementation. In Qt 4, in most
       
    92     situations, painting must occur within a widget's paint event
       
    93     handler.
       
    94 
       
    95     On X11, it is possible to set the \l{Qt::WA_PaintOutsidePaintEvent}
       
    96     attribute on widgets to keep existing code, but we recommend
       
    97     restricting the use of painting code to within paint event handlers
       
    98     where possible.
       
    99 
       
   100     More information about this change can be found in the
       
   101     \l{Porting to Qt 4#Painting and Redrawing Widgets}{Painting and Redrawing Widgets}
       
   102     section of the \l{Porting to Qt 4} document.
       
   103 
       
   104     \section2 Qt Designer
       
   105 
       
   106     The version of Qt Designer supplied with Qt 3 provided
       
   107     extensive code editing and project management features
       
   108     (control over \c{.ui.h} and \c{.pro} files), and encouraged
       
   109     users to design main window applications from within the
       
   110     Qt Designer environment.
       
   111 
       
   112     The version of Qt Designer supplied with Qt 4 is intended
       
   113     to be integrated with other software development tools (such
       
   114     as integrated development environments), and does not
       
   115     support these project-level features.
       
   116 
       
   117     We recommend using one of the
       
   118     \l{Using a Designer UI File in Your Application}{form subclassing approaches}
       
   119     with forms created using Qt Designer. This avoids the need
       
   120     to use \c{.ui.h} files and special purpose code editors.
       
   121 
       
   122     Existing Qt 3 forms created using Qt Designer can be gradually
       
   123     ported to Qt 4 by following the advice in the
       
   124     \l{Porting UI Files to Qt 4} guide. However, some extra effort
       
   125     will be required to move application logic from \c{.ui.h} files
       
   126     into the main body of a Qt 4 application.
       
   127 
       
   128     \section2 Menu Items (QMenuItem)
       
   129 
       
   130     The old-style construction of menus by creating individual
       
   131     menu items has been superseded in Qt 4 by the use of
       
   132     generic actions which can be used in menus, toolbars, and
       
   133     as keyboard shortcuts.
       
   134 
       
   135     Qt 3 also supports this action-based approach, so, by using
       
   136     QAction throughout your application, less work will be
       
   137     required to adapt your application to Qt 4.
       
   138 
       
   139     \section2 Pointer-Based Classes (QPtr*)
       
   140 
       
   141     Qt 3 provides a group of pointer-based classes (\c QPtrList,
       
   142     \c QPtrDict, \c QPtrVector, etc.) that help manage collections
       
   143     of pointers to objects (usually QObject subclasses) in an
       
   144     application. In addition, the value-based collection classes
       
   145     (\c QValueList, \c QValueDict, \c QValueVector, etc.) provide
       
   146     a way to store standard value types which cannot be easily stored
       
   147     in pointer-based collections.
       
   148 
       
   149     Qt 4 introduces a single set of collection classes which
       
   150     does not require developers to pay as much attention to
       
   151     memory allocation and object ownership issues. As a result,
       
   152     Qt 3's pointer-based classes have no direct equivalent
       
   153     classes in Qt 4.
       
   154 
       
   155     To ease migration, use Qt 3's value-based classes to store
       
   156     most objects, including pointers; for example, use
       
   157     \c QValueVector<QWidget *> rather than
       
   158     \c QPtrVector<QWidget *>. These can be replaced by
       
   159     Qt 4's QVector, QLinkedList, and QList later.
       
   160 
       
   161     \section2 Other Collection Classes (QStrList, Q*Dict)
       
   162 
       
   163     Some collection classes in Qt 3 have been deprecated in
       
   164     favor of easier to use, higher level alternatives. These
       
   165     include the dictionary classes (\c QAsciiDict, \c QDict,
       
   166     \c QIntDict, \c QPtrDict) and \c QStrList.
       
   167 
       
   168     \c QStrList can usually replaced by the higher level QStringList
       
   169     class in Qt 3; this is also available in Qt 4. It is
       
   170     recommended that you use the QMap class instead of the \c QDict
       
   171     classes. In Qt 4, QMap is also complemented by the QHash
       
   172     class.
       
   173 
       
   174     \section2 Memory Arrays (QMemArray)
       
   175 
       
   176     In Qt 3, the \c QMemArray class is used as a simple array
       
   177     container for simple data types. This class is deprecated in
       
   178     Qt 4 in favor of the QVector and QVarLengthVector classes
       
   179     which provide more powerful and consistent array objects.
       
   180 
       
   181     Qt 3's closest equivalent class to Qt 4's QVector is the
       
   182     \c QValueVector class. For many purposes, this can be used
       
   183     instead of \c QMemArray.
       
   184 
       
   185     \section2 URL Operations (QUrlOperator)
       
   186 
       
   187     The URL operator in Qt 3 provides an abstract way to
       
   188     handle files via HTTP, FTP, and on the local file system.
       
   189     However, Qt 4 only provides this functionality through the
       
   190     use of the Q3UrlOperator.
       
   191 
       
   192     From Qt 4.4, the Network Access API provides a subset of the features
       
   193     provided by \c QUrlOperator that are mostly intended for use with
       
   194     applications that use the HTTP and FTP protocols. See the
       
   195     QNetworkRequest, QNetworkReply, and QNetworkAccessManager documentation
       
   196     for further details.
       
   197 
       
   198     It is also possible to perform operations on remote files through
       
   199     the QNetworkAccessManager and QFtp classes, and on local files
       
   200     with the QFile class.
       
   201 
       
   202     \section2 SQL Cursors (QSqlCursor)
       
   203 
       
   204     In Qt 3, one of the preferred methods of working with SQL
       
   205     is to use a cursor to manipulate the contents of a database.
       
   206     In Qt 4, the preferred method of working with SQL is to use
       
   207     the model/view architecture (QSqlQueryModel and QSqlTableModel)
       
   208     and, as a result, the cursor interface is only supplied in the
       
   209     Q3SqlCursor class.
       
   210 
       
   211     The easiest way to ensure continuity between Qt 3 and Qt 4
       
   212     is to use QSqlQuery rather than \c QSqlCursor,
       
   213     and migrate to QSqlQueryModel later.
       
   214 
       
   215     \section2 Domain Name Service (QDns)
       
   216 
       
   217     The QDns class in Qt 4 provides a much simpler interface
       
   218     than the QDns class in Qt 3, and is mainly used for host
       
   219     name resolution.
       
   220     As a result, many of the more complex features of Qt 3's
       
   221     QDns class are only available through Qt 4's Q3Dns
       
   222     compatibility class.
       
   223 
       
   224     To resolve host names with Qt 3, it is recommended that you
       
   225     use the higher level interface of QSocket rather than QDns.
       
   226     The equivalent functionality is available in Qt 4 in the
       
   227     QAbstractSocket and QHostInfo classes.
       
   228 
       
   229     \section2 Wizard Dialogs (QWizard)
       
   230 
       
   231     Qt 3 provides support for "wizard" dialogs in the form of
       
   232     the \c QWizard class. Prior to Qt 4.3, this class was made
       
   233     available as Q3Wizard, and provides the same interface for
       
   234     creating relatively complex wizards.
       
   235 
       
   236     In Qt 4.3 and later, a revised QWizard class can be used to
       
   237     create this kind of dialog, but existing Qt 3 wizard
       
   238     implementations may need to be redesigned to work with the
       
   239     new QWizard API.
       
   240 
       
   241     \section2 Abstract Grid Views (QGridView)
       
   242 
       
   243     Before the introduction of the Qt 3 \c QTable class,
       
   244     \c QGridView was the recommended way to create tables of
       
   245     custom items.
       
   246     With the introduction of \c QTable, the \c QGridView class was
       
   247     effectively obsoleted, and the \c QTable class should now be
       
   248     used to display tabular information in your Qt 3 application.
       
   249     This approach allows you to use QTableWidget as a replacement
       
   250     when later porting your application to Qt 4.
       
   251 
       
   252     \section2 Specialized Scrolling Views
       
   253 
       
   254     In Qt 3, the \c QScrollView class provides a viewport that can
       
   255     be used to display part of a larger widget, and will
       
   256     optionally provide scroll bars for navigation purposes.
       
   257     In Qt 4, this functionality is superseded by classes such as
       
   258     QScrollArea, which provides a more intuitive interface for
       
   259     developers to use.
       
   260     \c QScrollView is available in Qt 4 as the Q3ScrollView class.
       
   261 
       
   262     In Qt 3, it is recommended that \c QScrollView should be
       
   263     used with child widgets rather than subclassed. However, it
       
   264     should be noted that this approach may not be appropriate if
       
   265     you need to use extremely large scrolling areas in your
       
   266     application, since Qt 3 widgets cannot be wider or taller
       
   267     than 32767 pixels.
       
   268 
       
   269     \section1 Significantly Changed Features
       
   270 
       
   271     Some Qt 3 features have changed significantly for Qt 4. 
       
   272     and the recommended way of using them has therefore changed
       
   273     significantly, too. This is most notably true for the drag 
       
   274     and drop API. 
       
   275 
       
   276     Additionally, some of the more specialized features in Qt 3 are
       
   277     often used to help customize widgets and add extra polish to an
       
   278     application.
       
   279     Although these improvements make applications more presentable to
       
   280     users, many of them are unnecessary with Qt 4, and may create
       
   281     additional porting work.
       
   282 
       
   283     \section2 Drag and Drop
       
   284 
       
   285     Qt 4 introduces a simpler and more intuitive implementation
       
   286     of drag and drop between widgets, and with other applications.
       
   287     As a result, there is no simple approach that can be used to
       
   288     make drag and drop in a Qt 3 application easier to port to
       
   289     Qt 4.
       
   290 
       
   291     \section2 Extensive Customization of Item Views
       
   292 
       
   293     Each of the classes that are used to display list, tree,
       
   294     and table items in Qt 3 can be subclassed for the purposes
       
   295     of customizing their appearance. The item view framework
       
   296     in Qt 4 is implemented according to a different paradigm
       
   297     (model/view) which does not allow items to be customized
       
   298     using this method.
       
   299 
       
   300     Although Qt 4 provides compatibility classes (Q3ListBoxItem,
       
   301     Q3ListViewItem, and Q3TableItem) that can be used in the same
       
   302     way as their Qt 3 counterparts, these cannot be used within
       
   303     the standard model/view framework. It is recommended that,
       
   304     to minimize porting effort, extensive customization of item
       
   305     classes should be avoided in Qt 3, if at all possible.
       
   306 
       
   307     \section2 Double Buffering
       
   308 
       
   309     Qt 3 applications often use double buffering for reducing
       
   310     flicker when painting custom widgets. This approach is
       
   311     unnecessary with Qt 4 because double buffering is
       
   312     automatically performed by the paint engine.
       
   313 
       
   314     It still makes sense to use double buffering in
       
   315     Qt 4 in certain contexts. For example, in
       
   316     Chapter 5 of \l{GUI Programming with Qt 3}, double buffering
       
   317     was presented as a speed optimization and not just as a means
       
   318     of reducing flicker.
       
   319 
       
   320     \section2 Data-Aware Forms
       
   321 
       
   322     The \c QDataTable, \c QDataBrowser, and \c QDataView classes
       
   323     in Qt 3 allow integration between widgets and SQL-based
       
   324     databases.
       
   325 
       
   326     In Qt 4.1 and earlier, the preferred way to create a data-aware
       
   327     widget is to connect an generic item view (such as a table view)
       
   328     to a SQL model. In Qt 4.2 and later, the QDataWidgetMapper class
       
   329     can be used to map data to widgets in a form-based user interface.
       
   330 
       
   331     New applications written with Qt 3 should use QSqlQuery in
       
   332     preference to an approach based on the old-style data-aware
       
   333     widgets.
       
   334     This offers a choice of porting strategies when later migrating
       
   335     the application to Qt 4: You can either continue to use
       
   336     QSqlQuery or take the opportunity to use the model/view
       
   337     classes to handle database integration.
       
   338 
       
   339     \section2 Dock Windows and Areas
       
   340 
       
   341     In Qt 4, the way that dock windows are constructed and used
       
   342     in main window applications differs significantly to the
       
   343     pattern of use provided by Qt 3. As a result, the introduction
       
   344     of a simpler and cleaner API means that Qt 3 applications that
       
   345     make extensive use of dock window areas will require careful
       
   346     examination when they are ported to Qt 4.
       
   347 
       
   348     We recommend that the QMainWindow class be used in preference
       
   349     to the Q3MainWindow compatibility class when an existing Qt 3
       
   350     main window application is ported to Qt 4. Therefore, we
       
   351     recommend that specialized use of dock window areas should
       
   352     be avoided when writing a Qt 3 application with Qt 4 in mind.
       
   353 
       
   354     \section2 Custom Styles
       
   355 
       
   356     The style system used to provide consistent themes for Qt's
       
   357     standard widgets has been revised for Qt 4. As a result,
       
   358     custom styles for Qt 3 require some porting work to be done
       
   359     before they can be used with Qt 4. To ease the porting process,
       
   360     we recommend that you avoid implementing custom widget styles
       
   361     for Qt 3 applications unless it is absolutely necessary for
       
   362     your users.
       
   363 
       
   364     In Qt 4.2 and later, \l{Qt Style Sheets} can be used to
       
   365     implement many common modifications to existing styles, and
       
   366     this may be sufficient for Qt 3 applications.
       
   367 
       
   368     \section2 Events
       
   369     In Qt 3, QCloseEvents were not accepted by default. In Qt 4,
       
   370     the event handler QWidget::closeEvent() receives QCloseEvents,
       
   371     and accepts them by default closing the application. To avoid 
       
   372     this, please reimplement QWidget::closeEvent().  
       
   373 */