Qt:Документация 4.3.2/qt4-intro
Материал из Wiki.crossplatform.ru
(Новая: {{Qt4.3.2_header}} [Next: The Tulip Container Classes ] =What's New in Qt 4<br />= This document covers the most important differenc...)
Следующая правка →
Версия 11:14, 29 января 2009
![]() | Внимание: Актуальная версия перевода документации находится здесь |
__NOTOC__
Главная · Все классы · Основные классы · Классы по группам · Модули · Функции |
[Next: The Tulip Container Classes ]
Содержание[убрать] |
What's New in Qt 4
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.
- New Technologies in Qt 4
- Recent Additions to Qt 4
- Significant Improvements
- Build System
- Include Syntax
- Пространства имен
- QObject/QWidget Constructors
- Dynamic Casts
- QPointer<T>
- Paint Events
- Qt 3 Support Layer
New Technologies in Qt 4
Qt 4 introduces the following core technologies:
- Tulip, a new set of template container classes.
- Interview, a model/view architecture for item views.
- Arthur, the Qt 4 painting framework.
- Scribe, the Unicode text renderer with a public API for performing low-level text layout.
- Mainwindow, a modern action-based mainwindow, toolbar, menu, and docking architecture.
- The new Qt Designer user interface design tool.
Recent Additions to Qt 4
The following features have been added to Qt since the first release of Qt 4:
In Qt 4.2:
- The Graphics View framework for producing interactive graphics.
- Desktop integration facilities for applications.
- Qt Style Sheets enable easy, yet powerful customization of user interfaces.
- Support for the D-Bus Inter-Process Communication (IPC) and Remote Procedure Calling (RPC) mechanism.
- An Undo framework based on the Command pattern.
- Support for model-based text completion in standard and custom widgets.
- New widgets and GUI features, such as QCalendarWidget and QGLFramebufferObject.
- Classes to provide higher level application infrastructure, such as QFileSystemWatcher and QDataWidgetMapper.
In Qt 4.1:
- Integrated support for rendering Scalable Vector Graphics (SVG) drawings and animations.
- Support for child widget transparency on all platforms.
- A Portable Document Format (PDF) backend for Qt's printing system.
- A unit testing framework for Qt applications and libraries.
- Modules for extending Qt Designer and dynamic user interface building.
- New proxy models to enable view-specific sorting and filtering of data displayed using item views.
- Support for universal binaries on Mac OS X.
- Additional features for developers using OpenGL, such as support for pixel and sample buffers.
- A flexible syntax highlighting class based on the Scribe rich text framework.
- Support for network proxy servers using the SOCKS5 protocol.
- Support for OLE verbs and MIME data handling in ActiveQt.
For more information about improvements in the current release, see the detailed list of changes.
Significant Improvements
The following modules have been significantly improved for Qt 4:
- A fully cross-platform accessibility module, with support for the emerging SP-API Unix standard in addition to Microsoft and Mac Accessibility.
- The SQL module, which is now based on the Interview model/view framework.
- The network module, with better support for UDP and synchronous sockets.
- The style API, which is now decoupled from the widgets, meaning that you can draw any user interface element on any device (widget, pixmap, etc.).
- Enhanced thread support, with signal-slot connections across threads and per-thread event loops.
- A new resource system for embedding images and other resource files into the application executable.
Build System
Unlike previous Qt releases, Qt 4 is a collection of smaller libraries:
Library | Описание |
---|---|
QtCore | Core non-GUI functionality |
QtGui | Core GUI functionality |
QtNetwork | Network module |
QtOpenGL | OpenGL module |
QtSql | SQL module |
QtSvg | SVG rendering classes |
QtXml | XML module |
Qt3Support | Qt 3 support classes |
QAxContainer | ActiveQt client extension |
QAxServer | ActiveQt server extension |
QtAssistant | Classes for launching Qt Assistant |
QtDesigner | Classes for extending and embedding Qt Designer |
QtUiTools | Classes for dynamic GUI generation |
QtTest | Классы инструментов для тестирования элементов |
QtCore contains tool classes like QString, QList, and QFile, as well as kernel classes like QObject and QTimer. The QApplication class has been refactored so that it can be used in non-GUI applications. It is split into QCoreApplication (in QtCore) and QApplication (in QtGui).
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).
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
QT -= gui
to your .pro file. To enable the other libraries, add the line
QT += network opengl sql qt3support
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.
To compile code that uses .ui files, you will also need this line in the .pro file:
CONFIG += uic3
Include Syntax
The syntax for including Qt class definitions has become
#include <QClassName>
Пример:
#include <QString> #include <QApplication> #include <QSqlTableModel>
This is guaranteed to work for any public Qt class. The old syntax,
#include <qclassname.h>
still works, but we encourage you to switch to the new syntax.
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., " QSqlQuery: 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 .pro file (see Build System above).
To include the definitions for all the classes in a library, simply specify the name of that library. Пример:
#include <QtCore>
Пространства имен
Qt 2 introduced a class called Qt for global-like constants (e.g., Qt::yellow). The C++ namespace construct was not used because not all compilers understood it when it was released.
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 Qt:: (e.g., Qt::yellow), or add the directive
using namespace Qt;
at the top of your source files, after your #include directives. If you use the using namespace syntax you don't need the prefix (e.g., yellow is sufficient).
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 QWidget::yellow instead of Qt::yellow, because QWidget inherited from Qt. This won't work in Qt 4; you must write Qt::yellow or add the "using namespace" directive and drop the Qt:: prefix.
The qt3to4 porting tool automates this conversion.
QObject/QWidget Constructors
In Qt 4 we have tried to simplify the constructors of QObject/ QWidget subclasses. This makes subclassing easier, at the same time as it helps make the Qt library more efficient.
Constructors no longer take a "const char *name" parameter. If you want to specify a name for a QObject, you must call QObject::setObjectName() after construction. The object name is now a QString. The reasons for this change are:
- Code that used it looked confusing, for example:
QLabel *label1 = new QLabel("Hello", this); QLabel *label2 = new QLabel(this, "Hello");
label1 is a QLabel that displays the text "Hello"; label2 is a QLabel with no text, with the object name "Hello".
- 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. Пример:
MyWidget::MyWidget(QWidget *parent, const char *name) : QWidget(parent, name) {