1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/doc/porting2.doc:36 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Porting to Qt 2.x</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Porting to Qt 2.x</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | <p> <p>
|
---|
37 | You're probably looking at this page because you want to port
|
---|
38 | your application from Qt 1.x to Qt 2.x, but to be sure, let's
|
---|
39 | review the good reasons to do this:
|
---|
40 | <ul>
|
---|
41 | <li>To get access to all the new Qt 2.x features like the rich text
|
---|
42 | HTML subset for formatted labels, tooltips, online help etc.
|
---|
43 | and the much easier to use layout classes and widgets.
|
---|
44 | <li>To make your application truly international, with support
|
---|
45 | for Unicode and translations for the languages of the world.
|
---|
46 | <li>To allow your application to fit into the new look of the
|
---|
47 | Unix desktop with configurable, very powerful "themes". The
|
---|
48 | extended style system also integrates Qt applications better
|
---|
49 | on MS-Windows desktops. Qt will automatically chose the right
|
---|
50 | colors and fonts and obey global system setting changes.
|
---|
51 | <li>To stay up-to-date with the version of Qt that gets all the
|
---|
52 | new features and bug-fixes.
|
---|
53 | <li>To get more speed and smoother widgets display with all the
|
---|
54 | new anti-flicker changes in Qt.
|
---|
55 | <li>Most of all though, you want to port to Qt 2.x
|
---|
56 | so that your Wheel Mouse works!
|
---|
57 | </ul>
|
---|
58 | <p> <p>
|
---|
59 | The Qt 2.x series is not binary compatible with the 1.x series.
|
---|
60 | This means programs compiled for Qt 1.x must be recompiled to work
|
---|
61 | with Qt 2.x. Qt 2.x is also not completely <em>source</em> compatible
|
---|
62 | with 1.x, however all points of incompatibility cause
|
---|
63 | compiler errors (rather than mysterious results), or produce run-time
|
---|
64 | messages. The result is that Qt 2.x includes many additional features,
|
---|
65 | discards obsolete functionality that is easily converted to use the new
|
---|
66 | features, and that porting an application from Qt 1.x to Qt 2.x is
|
---|
67 | a simple task well worth the amount of effort required.
|
---|
68 | <p> To port code using Qt 1.x to use Qt 2.x:
|
---|
69 | <p> <ul>
|
---|
70 | <li> Briefly read the porting notes below to get an idea of what to expect.
|
---|
71 | <li> Be sure your code compiles and runs well on all your target platforms with Qt 1.x.
|
---|
72 | <li> Recompile with Qt 2.x. For each error, search below for related
|
---|
73 | identifiers (eg. function names, class names) - this documented is
|
---|
74 | structured to mention all relevant identifiers to facilitate such
|
---|
75 | searching, even if that makes it a little verbose.
|
---|
76 | <li> If you get stuck, ask on the qt-interest mailing list, or
|
---|
77 | Trolltech Technical Support if you're a Professional Edition
|
---|
78 | licensee.
|
---|
79 | </ul>
|
---|
80 | <p> Many very major projects, such as <a href="http://www.kde.org/">KDE</a>
|
---|
81 | have been port, so there is plenty of expertise in the collective conscious
|
---|
82 | that is the Qt Developer Community!
|
---|
83 | </p>
|
---|
84 | <p> <hr>
|
---|
85 | <p> <h2 align=center>The Porting Notes</h2>
|
---|
86 | <p> <ul>
|
---|
87 | <li><b><a href="#Namespace">Namespace</a></b>
|
---|
88 | <li><b><a href="#Virtual">Virtual Functions</a></b>
|
---|
89 | <li><b><a href="#Collection">Collection classes</a></b>
|
---|
90 | <li><b><a href="#DefaultParent">No Default 0 Parent Widget</a></b>
|
---|
91 | <li><b><a href="#DebugVsRelease">Debug vs. Release</a></b>
|
---|
92 | <li><b><a href="#QApplication">QApplication</a></b>
|
---|
93 | <li><b><a href="#QClipboard">QClipboard</a></b>
|
---|
94 | <li><b><a href="#QColor">QColor</a></b>
|
---|
95 | <li><b><a href="#QDataStream">QDataStream</a></b>
|
---|
96 | <li><b><a href="#QDialog">QDialog</a></b>
|
---|
97 | <li><b><a href="#QDropSite">QDropSite</a></b>
|
---|
98 | <li><b><a href="#QEvent">QEvent</a></b>
|
---|
99 | <li><b><a href="#QFile">QFile</a></b>
|
---|
100 | <li><b><a href="#QFontMetrics">QFontMetrics</a></b>
|
---|
101 | <li><b><a href="#QIODevice">QIODevice</a></b>
|
---|
102 | <li><b><a href="#QLabel">QLabel</a></b>
|
---|
103 | <li><b><a href="#QLayout">QLayout</a></b>
|
---|
104 | <li><b><a href="#QListView">QListView</a></b>
|
---|
105 | <li><b><a href="#QMenuData">QMenuData</a></b>
|
---|
106 | <li><b><a href="#QMenuData">QPopupMenu</a></b>
|
---|
107 | <li><b><a href="#QMultiLineEdit">QMultiLineEdit</a></b>
|
---|
108 | <li><b><a href="#QPainter">QPainter</a></b>
|
---|
109 | <li><b><a href="#QPicture">QPicture</a></b>
|
---|
110 | <li><b><a href="#QPoint">QPoint, <a href="qpointarray.html">QPointArray</a>, <a href="qsize.html">QSize</a> and <a href="qrect.html">QRect</a></a></b>
|
---|
111 | <li><b><a href="#QPixmap">QPixmap</a></b>
|
---|
112 | <li><b><a href="#QRgb">QRgb</a></b>
|
---|
113 | <li><b><a href="#QScrollView">QScrollView</a></b>
|
---|
114 | <li><b><a href="#QStrList">QStrList</a></b>
|
---|
115 | <li><b><a href="#QString">QString</a></b>
|
---|
116 | <li><b><a href="#QTextStream">QTextStream</a></b>
|
---|
117 | <li><b><a href="#QUriDrag">QUriDrag / QUrlDrag</a></b>
|
---|
118 | <li><b><a href="#QValidator">QComboBox</a></b>
|
---|
119 | <li><b><a href="#QValidator">QLineEdit</a></b>
|
---|
120 | <li><b><a href="#QValidator">QSpinBox</a></b>
|
---|
121 | <li><b><a href="#QValidator">QValidator</a></b>
|
---|
122 | <li><b><a href="#QWidget">QWidget</a></b>
|
---|
123 | <li><b><a href="#QWindow">QWindow</a></b>
|
---|
124 | </ul>
|
---|
125 | <p> <hr>
|
---|
126 | <p> <h3><a name="Namespace">Namespace</a></h3>
|
---|
127 | <p> <p> Qt 2.x is namespace-clean, unlike 1.x. Qt now uses very few
|
---|
128 | global identifiers. Identifiers like <code>red, blue, LeftButton,
|
---|
129 | AlignRight, Key_Up, Key_Down, NoBrush</code> etc. are now part of a
|
---|
130 | special class <code>Qt</code> (defined in qnamespace.h),
|
---|
131 | which is inherited by
|
---|
132 | most Qt classes. Member functions of classes that inherit from <a href="qwidget.html">QWidget</a>,
|
---|
133 | etc. are totally unaffected, but code that is
|
---|
134 | <em>not</em> in functions of classes inherited from <code>Qt</code>,
|
---|
135 | you must qualify these identifiers like this: <code>Qt::red,
|
---|
136 | Qt::LeftButton, Qt::AlignRight</code>, etc.
|
---|
137 | <p> <p>The <code>qt/bin/qt20fix</code> script helps to fix the code that
|
---|
138 | needs adaption, though most code does not need changing.
|
---|
139 | <p> Compiling with -DQT1COMPATIBILITY will help you get going with Qt 2.x
|
---|
140 | - it allows all the old "dirty namespace" identifiers from Qt 1.x to
|
---|
141 | continue working. Without it, you'll get compile errors that can
|
---|
142 | easily be fixed by searching this page for the clean identifiers.
|
---|
143 | <p> <h3><a name="DefaultParent">No Default 0 Parent Widget</a></h3>
|
---|
144 | <p> In Qt 1.x, all widget constructors were defined with a default value
|
---|
145 | of 0 for the parent widget. However, only the main window of the
|
---|
146 | application should be created with a 0 parent, all other widgets
|
---|
147 | should have parents. Having the 0 default made it too simple to create
|
---|
148 | bugs by forgetting to specify the parent of non-mainwindow
|
---|
149 | widgets. Such widgets would typically never be deleted (causing memory
|
---|
150 | leaks), and they would become top-level widgets, confusing the window
|
---|
151 | managers. Therefore, in Qt 2.x the 0 default parent has been removed
|
---|
152 | for the widget classes that are not likely to be used as main windows.
|
---|
153 | <p> Note also that programs no longer need (or should) use 0 parent just
|
---|
154 | to indicate that a widget should be top-level. See
|
---|
155 | <pre> QWidget::isTopLevel() </pre>
|
---|
156 | for details. See also the notes about
|
---|
157 | <a href="#QMenuData">QPopupMenu</a> and <a href="#QDialog">QDialog</a>
|
---|
158 | below.
|
---|
159 | <p> <h3><a name="Virtual">Virtual Functions</a></h3>
|
---|
160 | <p> <p> Some virtual functions have changed signature in Qt 2.x.
|
---|
161 | If you override them in derived classes, you must change the signature
|
---|
162 | of your functions accordingly.
|
---|
163 | <p> <!-- warwick can check for additions to this with his qt-2-report -->
|
---|
164 | <ul>
|
---|
165 | <li><pre> QWidget::setStyle(GUIStyle)</pre>
|
---|
166 |
|
---|
167 | <li><pre> QListView::addColumn(const char *, int)</pre>
|
---|
168 |
|
---|
169 | <li><pre> QListView::setColumnText(int, const char *)</pre>
|
---|
170 |
|
---|
171 | <li><pre> QListViewItem::setText(int, const char *)</pre>
|
---|
172 |
|
---|
173 | <li><pre> QMultiLineEdit::insertLine(const char *, int)</pre>
|
---|
174 |
|
---|
175 | <li><pre> QMultiLineEdit::insertAt(const char *, int, int, bool)</pre>
|
---|
176 |
|
---|
177 | <li><pre> QSpinBox::setPrefix(const char *)</pre>
|
---|
178 |
|
---|
179 | <li><pre> QSpinBox::setSuffix(const char *)</pre>
|
---|
180 |
|
---|
181 | <li><pre> QToolButton::setTextLabel(const char *, bool)</pre>
|
---|
182 |
|
---|
183 | <li><pre> QDoubleValidator::validate(QString &, int &)</pre>
|
---|
184 |
|
---|
185 | <li><pre> QIntValidator::validate(QString &, int &)</pre>
|
---|
186 |
|
---|
187 | <li><pre> QValidator::fixup(QString &)</pre>
|
---|
188 |
|
---|
189 | <li><pre> QSlider::paintSlider(QPainter *, const <a href="qrect.html">QRect</a> &)</pre>
|
---|
190 |
|
---|
191 | </ul>
|
---|
192 | <p> This is one class of changes that are
|
---|
193 | not detected by the compiler,
|
---|
194 | so you should mechanically search for each of
|
---|
195 | these function names in your header files, eg.
|
---|
196 | <p> <pre>
|
---|
197 | egrep -w 'setStyle|addColumn|setColumnText|setText...' *.h
|
---|
198 | </pre>
|
---|
199 |
|
---|
200 | <p> Of course, you'll get a few false positives (eg. if you have a setText
|
---|
201 | function that is not in a subclass of <a href="qlistviewitem.html">QListViewItem</a>).
|
---|
202 | <p> <h3><a name="Collection">Collection classes</a></h3>
|
---|
203 | <p> <p> The <a href="collection.html#collection-classes">collection classes</a> include generic
|
---|
204 | classes such as QGDict, QGList, and
|
---|
205 | the subclasses such as <a href="qdict.html">QDict</a> and QList.
|
---|
206 | <p> <p> The macro-based Qt collection classes are obsolete; use the
|
---|
207 | template-based classes instead. Simply remove includes of qgeneric.h and
|
---|
208 | replace e.g. Q_DECLARE(<a href="qcache.html">QCache</a>,QPixmap) with QCache<QPixmap>.
|
---|
209 | <p> <p> The GCI global typedef is replaced by QCollection::Item. Only if you
|
---|
210 | make your own subclasses of the undocumented generic collection classes
|
---|
211 | will you have GCI in your code.
|
---|
212 | This change has been made to avoid collisions with other namespaces.
|
---|
213 | <p> <p> The GCF global typedef is removed (it was not used in Qt).
|
---|
214 | <p> <h3><a name="DebugVsRelease">Debug vs. Release</a></h3>
|
---|
215 | <p> <p>The Q_ASSERT macro is now a null expression if the QT_CHECK_STATE flag
|
---|
216 | is not set (i.e. if the QT_NO_CHECK flag is defined).
|
---|
217 | <p> <p>The debug() function now outputs nothing if Qt was compiled with
|
---|
218 | the QT_NO_DEBUG macro defined.
|
---|
219 | <p> <h3><a name="QString">QString</a></h3>
|
---|
220 | <p> <a href="qstring.html">QString</a> has undergone major changes internally, and although it is highly
|
---|
221 | backward compatible, it is worth studying in detail when porting to Qt 2.x.
|
---|
222 | The Qt 1.x QString class has been renamed to <a href="qcstring.html">QCString</a> in Qt 2.x, though if
|
---|
223 | you use that you will incur a performance penalty since all Qt functions
|
---|
224 | that took const char* now take const QString&.
|
---|
225 | <p> <p>
|
---|
226 | To take full advantage of the new <a href="i18n.html#internationalization">Internationalization</a>
|
---|
227 | functionality in Qt 2.x, the following steps are required:
|
---|
228 | <p> <ul>
|
---|
229 | <li> Start converting all uses of "const char*" in parameters to
|
---|
230 | "const QString&" - this can often be done mechanically, eg.
|
---|
231 | using Perl. Convert usage of char[] for temporary string
|
---|
232 | building to QString (much software already uses QString for
|
---|
233 | this purpose as it offers many more facilities).
|
---|
234 | <p> If you find that you are mixing usage of QCString, QString,
|
---|
235 | and <a href="qbytearray.html">QByteArray</a>, this causes lots of unnecessary copying and
|
---|
236 | might indicate that the true nature of the data you are
|
---|
237 | dealing with is uncertain. If the data is NUL-terminated
|
---|
238 | 8-bit data, use QCString; if it is unterminated (ie.
|
---|
239 | contains NULs) 8-bit data, use QByteArray; if it is text,
|
---|
240 | use <a href="qstring.html">QString</a>.
|
---|
241 | </p>
|
---|
242 | <li> Put a breakpoint in <pre> QString::latin1()</pre>
|
---|
243 |
|
---|
244 | to catch places where
|
---|
245 | Unicode information is being converted to ASCII (loosing
|
---|
246 | information if your user in not using Latin1). Qt has
|
---|
247 | a small number of calls to this - ignore those. As a stricter
|
---|
248 | alternative, compile your code with QT_NO_ASCII_CAST defined,
|
---|
249 | which hides the automatic conversion of QString to const char*,
|
---|
250 | so you can catch problems at compile time.
|
---|
251 | </p>
|
---|
252 | <li> See the Qt <a href="i18n.html">Internationalization page</a>
|
---|
253 | for information about the full process of internationalizing
|
---|
254 | your software.
|
---|
255 | </ul>
|
---|
256 | <p> <p>
|
---|
257 | Points to note about the new QString are:
|
---|
258 | <p> <dl compact>
|
---|
259 | <dt><b>Unicode</b></dt>
|
---|
260 | <dd>
|
---|
261 | Qt now uses Unicode throughout.
|
---|
262 | data() now returns a <em>const</em> reference to an ASCII version
|
---|
263 | of the string - you cannot directly access the
|
---|
264 | string as an array of bytes, because it isn't one. Often, latin1() is
|
---|
265 | what you want rather than data(), or just leave it to convert to
|
---|
266 | const char* automatically. data() is only used now to aide porting to Qt 2.x,
|
---|
267 | and ideally you'll only need latin1() or implicit conversion when interfacing
|
---|
268 | to facilities that do not have Unicode support.
|
---|
269 | <p> <dt><b>Automatic-expanding</b></dt>
|
---|
270 | <dd>
|
---|
271 | A big advantage of the new <a href="qstring.html">QString</a> is that it automatically expands
|
---|
272 | when you write to an indexed position.
|
---|
273 | <p> <dt><b>QChar and <a href="qcharref.html">QCharRef</a></b></dt>
|
---|
274 | <dd>
|
---|
275 | <a href="qchar.html">QChar</a> are the Unicode characters that make up a QString. A QCharRef is
|
---|
276 | a temporary reference to a QChar in a QString that when assigned to
|
---|
277 | ensures that the <a href="shclass.html#implicit-sharing">implicit sharing</a> semantics of the QString are maintained.
|
---|
278 | You are unlikely to use QCharRef in your own code - but so that you
|
---|
279 | understand compiler error messages, just know that <tt>mystring[123]</tt>
|
---|
280 | is a QCharRef whenever <tt>mystring</tt> is not a constant string. A QCharRef
|
---|
281 | has basically the same functionality as a QChar, except it is more restricted
|
---|
282 | in what you can assign to it and cast it to (to avoid programming errors).
|
---|
283 | <p> <dt><b>Use QString</b></dt>
|
---|
284 | <dd>
|
---|
285 | Try to always use QString. If you <em>must</em>, use <a href="qcstring.html">QCString</a> which is the
|
---|
286 | old implementation from Qt 1.x.
|
---|
287 | <p> <dt><b>Unicode vs. ASCII</b></dt>
|
---|
288 | <dd>
|
---|
289 | Every conversion to and from ASCII is wasted time, so try to use <a href="qstring.html">QString</a>
|
---|
290 | as much as possible rather than const char*. This also ensures you have
|
---|
291 | full 16-bit support.
|
---|
292 | <p> <dt><b>Convertion to ASCII</b></dt>
|
---|
293 | <dd>
|
---|
294 | The return value from operator const char*() is transient - don't expect
|
---|
295 | it to remain valid while you make deep function calls.
|
---|
296 | It is valid for as long as you don't modify or destroy the QString.
|
---|
297 | <p> <dt><b>QString is simpler</b></dt>
|
---|
298 | <dd>
|
---|
299 | Expect your code to become simpler with the new QString, especially
|
---|
300 | places where you have used a char* to wander over the string rather
|
---|
301 | than using indexes into the string.
|
---|
302 | <p> <dt><b>Some hacks don't work</b></dt>
|
---|
303 | <dd>
|
---|
304 | This hack:
|
---|
305 | use_sub_string( &my_string[index] )
|
---|
306 | should be replaced by:
|
---|
307 | use_sub_string( my_string.mid(index) )
|
---|
308 | <p> <dt><b>QString(const char*, int) is removed</b></dt>
|
---|
309 | <dd>
|
---|
310 | The QString constructor taking a const char* and an integer is removed.
|
---|
311 | Use of this constructor was error-prone, since the length included the
|
---|
312 | '\0' terminator. Use <a href="qstring.html#left">QString::left</a>(int) or <a href="qstring.html#fromLatin1">QString::fromLatin1</a>( const char*,
|
---|
313 | int ) -- in both cases the int parameter signifies the number of characters.
|
---|
314 | <p> <dt><b>QString(int) is private</b></dt>
|
---|
315 | <dd>
|
---|
316 | The <a href="qstring.html">QString</a> constructor taking an integer is now private. This function
|
---|
317 | is not meaningful anymore, since QString does all space allocation
|
---|
318 | automatically. 99% of cases can simple be changed to use the
|
---|
319 | default constructor, QString().
|
---|
320 | <p>
|
---|
321 | In Qt 1.x the constructor was used in two ways: accidentally,
|
---|
322 | by attempting to convert a char to a QString (the char converts to int!) -
|
---|
323 | giving strange bugs, and as a way to make a QString big enough prior to
|
---|
324 | calling <pre> QString::sprintf()</pre>
|
---|
325 | . In Qt 2.x, the accidental bug case is
|
---|
326 | prevented (you will get a compilation error) and QString::sprintf has
|
---|
327 | been made safe - you no longer need to pre-allocate space (though for
|
---|
328 | other reasons, sprintf is still a poor choice - eg. it doesn't pass Unicode).
|
---|
329 | The only remaining common case is conversion of 0 (NULL) to QString, which
|
---|
330 | would usually give expected results in Qt 1.x. For Qt 2.x the correct
|
---|
331 | syntax is to use <a href="qstring.html#QString-null">QString::null</a>, though note that
|
---|
332 | the default constructor, QString(), creates a null string too.
|
---|
333 | Assignment of 0 to a <a href="qstring.html">QString</a> is ambiguous - assign
|
---|
334 | QString::null; you'll mainly find these in code that has been converted
|
---|
335 | from const char* types to QString.
|
---|
336 | This also prevents a common error case from Qt 1.x - in
|
---|
337 | that version, mystr = 'X' would <em>not</em> produce the expected
|
---|
338 | results and was always a programming error; in Qt 2.x, it works - making
|
---|
339 | a single-character string.
|
---|
340 | <p> <p>
|
---|
341 | Also see <a href="#QStrList">QStrList</a>.
|
---|
342 | <p> <dt><b>Signals and Slots</b></dt>
|
---|
343 | <dd>
|
---|
344 | Many signal/slots have changed from const char* to QString. You will
|
---|
345 | get run-time errors when you try to <pre> QObject::connect()</pre>
|
---|
346 |
|
---|
347 | to the old
|
---|
348 | signals and slots, usually with a message indicating the const QString&
|
---|
349 | replacement signal/slot.
|
---|
350 | <p> <dt><b>Optimize with Q2HELPER</b></dt>
|
---|
351 | <dd>
|
---|
352 | In qt/src/tools/qstring.cpp there is a Q2HELPER - define it for some
|
---|
353 | extra debugging/optimizing features (don't leave it it - it kills performance).
|
---|
354 | You'll get an extra function, qt_qstring_stats(), which will print a
|
---|
355 | summary of how much your application is doing Unicode and ASCII
|
---|
356 | back-and-forth conversions.
|
---|
357 | <p> <dt><b>QString::detach() is obsolete and removed</b></dt>
|
---|
358 | <dd>
|
---|
359 | Since <a href="qstring.html">QString</a> is now always shared, this function does nothing.
|
---|
360 | Remove calls to QString::detach().
|
---|
361 | <p> <dt><b>QString::resize(int size) is obsolete and removed</b></dt>
|
---|
362 | <dd>
|
---|
363 | Code using this to truncate a string should use
|
---|
364 | <a href="qstring.html#truncate">truncate(size-1)</a>.
|
---|
365 | Code using qstr.resize(0) should use qstr = QString::null.
|
---|
366 | Code calling resize(n) prior to using
|
---|
367 | <a href="qstring.html#operator[]">operator[]</a> up to n just remove
|
---|
368 | the resize(n) completely.
|
---|
369 | <p> <dt><b>QString::size() is obsolete and removed</b></dt>
|
---|
370 | <dd>
|
---|
371 | Calls to this function must be replaced by
|
---|
372 | <a href="qstring.html#length">length()</a>+1.
|
---|
373 | <p> <dt><b>QString::setStr(const char*) is removed</b></dt>
|
---|
374 | <dd>Try to understand why you were using this.
|
---|
375 | If you just meant assignment, use that. Otherwise,
|
---|
376 | you are probably using QString as an array of bytes, in which case use
|
---|
377 | <a href="qbytearray.html">QByteArray</a> or <a href="qcstring.html">QCString</a> instead.
|
---|
378 | <p> <dt><b>QString is not an array of bytes</b></dt>
|
---|
379 | <dd>
|
---|
380 | Code that uses <a href="qstring.html">QString</a> as an array of bytes should use QByteArray
|
---|
381 | or a char[], <em>then</em> convert that to a QString if needed.
|
---|
382 | <p> <dt><b>"string = 0"</b></dt>
|
---|
383 | <dd>
|
---|
384 | Assigning 0 to a QString should be assigning the null string,
|
---|
385 | ie. string = QString::null.
|
---|
386 | <p> <dt><b>System functions</b></dt>
|
---|
387 | <dd>
|
---|
388 | You may find yourself needing latin1() for passing to the operating system
|
---|
389 | or other libraries, and be tempted to use QCString to save the conversion,
|
---|
390 | but you are better off using Unicode throughout, then when the operating
|
---|
391 | system supports Unicode, you'll be prepared. Some Unix operating systems
|
---|
392 | are now beginning to have basic Unicode support, and Qt will be tracking
|
---|
393 | these improvements as they become more widespread.
|
---|
394 | <p> <dt><b>Bugs removed</b></dt>
|
---|
395 | <dd>
|
---|
396 | toShort() returns 0 (and sets *ok to false) on error.
|
---|
397 | toUInt() now works for big valid unsigned integers.
|
---|
398 | insert() now works into the same string.
|
---|
399 | <p> <dt><b>NULL pointers</b></dt>
|
---|
400 | <dd>
|
---|
401 | When converting "const char*" usage to QString in order to make your
|
---|
402 | application fully Unicode-aware, use QString::null for the null value
|
---|
403 | where you would have used 0 with char pointers.
|
---|
404 | <p> <dt><b>QString is not null terminated</b></dt>
|
---|
405 | <dd>
|
---|
406 | This means that inserting a 0-character
|
---|
407 | in the middle of the string does <em>not</em> change the length(). ie.
|
---|
408 | <pre>
|
---|
409 | <a href="qstring.html">QString</a> s = "fred";
|
---|
410 | s[1] = '\0';
|
---|
411 | // s.<a href="qstring.html#length">length</a>() == 4
|
---|
412 | // s == "f\0ed"
|
---|
413 | // s.<a href="qstring.html#latin1">latin1</a>() == "f"
|
---|
414 | s[1] = 'r';
|
---|
415 | // s == "fred"
|
---|
416 | // s.<a href="qstring.html#latin1">latin1</a>() == "fred"
|
---|
417 | </pre>
|
---|
418 |
|
---|
419 | Especially look out for this type of code:
|
---|
420 | <pre>
|
---|
421 | <a href="qstring.html">QString</a> s(2);
|
---|
422 | s[0] = '?';
|
---|
423 | s[1] = 0;
|
---|
424 | </pre>
|
---|
425 |
|
---|
426 | This creates a string 2 characters long.
|
---|
427 | To find these problems while converting, you might like to
|
---|
428 | add <a href="qapplication.html#Q_ASSERT">Q_ASSERT</a>(strlen(d->ascii)==d->len) inside
|
---|
429 | <pre> QString::latin1()</pre>
|
---|
430 | .
|
---|
431 | <p> <dt><b>QString or Standard C++ string?</b></dt>
|
---|
432 | <dd>
|
---|
433 | <p>
|
---|
434 | The Standard C++ Library string is not Unicode. Nor is wstring defined
|
---|
435 | to be so (for the small number of platforms where it is defined at all).
|
---|
436 | This is the same mistake made over and over
|
---|
437 | in the history of C - only when non-8-bit characters are <em>the norm</em>
|
---|
438 | do programmers find them usable. Though it is possible to convert between
|
---|
439 | string and <a href="qstring.html">QString</a>, it is less efficient than using QString throughout.
|
---|
440 | For example, when using:
|
---|
441 | <pre>
|
---|
442 | QLabel::<a href="qlabel.html#setText">setText</a>( const <a href="qstring.html">QString</a>& )
|
---|
443 | </pre>
|
---|
444 |
|
---|
445 | if you use string, like this:
|
---|
446 | <pre>
|
---|
447 | void myclass::dostuffwithtext( const string& str )
|
---|
448 | {
|
---|
449 | mylabel.setText( QString(str.c_str()) );
|
---|
450 | }
|
---|
451 | </pre>
|
---|
452 |
|
---|
453 | that will create a (ASCII only) copy of str, stored in mylabel.
|
---|
454 | But this:
|
---|
455 | <pre>
|
---|
456 | void myclass::dostuffwithtext( const <a href="qstring.html">QString</a>& str )
|
---|
457 | {
|
---|
458 | mylabel.setText( str );
|
---|
459 | }
|
---|
460 | </pre>
|
---|
461 |
|
---|
462 | will make an <a href="shclass.html#implicitly-shared">implicitly shared</a> reference to str in the <a href="qlabel.html">QLabel</a> - no copying
|
---|
463 | at all. This function might be 10 nested function calls away from something
|
---|
464 | like this:
|
---|
465 | <pre>
|
---|
466 | void toplevelclass::initializationstuff()
|
---|
467 | {
|
---|
468 | doStuff( tr("Okay") );
|
---|
469 | }
|
---|
470 | </pre>
|
---|
471 |
|
---|
472 | At this point, in Qt 2.x, the tr() does a very fast dictionary lookup
|
---|
473 | through memory-mapped message files, returning some Unicode <a href="qstring.html">QString</a> for
|
---|
474 | the appropriate language (the default being to just make a QString out
|
---|
475 | of the text, of course - you're not <em>forced</em> to use any of these
|
---|
476 | features), and that <em>same</em> memory mapped Unicode will be passed
|
---|
477 | though the system. All occurrences of the translation of "Okay" can
|
---|
478 | potentially be shared.
|
---|
479 | <p> </dl>
|
---|
480 | <p> <h3><a name="QApplication">QApplication</a></h3>
|
---|
481 | <p> In the function <pre> QApplication::setColorSpec()</pre>
|
---|
482 | ,
|
---|
483 | PrivateColor and TrueColor are obsolete. Use ManyColor instead.
|
---|
484 | <p> <h3><a name="QColor">QColor</a></h3>
|
---|
485 | <p> <p>
|
---|
486 | All colors
|
---|
487 | (color0,
|
---|
488 | color1,
|
---|
489 | black,
|
---|
490 | white,
|
---|
491 | darkGray,
|
---|
492 | gray,
|
---|
493 | lightGray,
|
---|
494 | red,
|
---|
495 | green,
|
---|
496 | blue,
|
---|
497 | cyan,
|
---|
498 | magenta,
|
---|
499 | yellow,
|
---|
500 | darkRed,
|
---|
501 | darkGreen,
|
---|
502 | darkBlue,
|
---|
503 | darkCyan,
|
---|
504 | darkMagenta,
|
---|
505 | and
|
---|
506 | darkYellow)
|
---|
507 | are in the Qt namespace.
|
---|
508 | In members of classes that inherit the Qt namespace-class (eg. <a href="qwidget.html">QWidget</a>
|
---|
509 | subclasses), you can use the unqualified names as before, but in global
|
---|
510 | functions (eg. main()), you need to qualify them: Qt::red, Qt::white, etc.
|
---|
511 | See also the <a href="#QRgb">QRgb</a> section below.
|
---|
512 | <p> <h3><a name="QRgb">QRgb</a></h3>
|
---|
513 | <p> In QRgb (a typedef of long), the order of the RGB channels has changed to
|
---|
514 | be in the more efficient order (for typical contemporary hardware). If your
|
---|
515 | code made assumptions about the order, you will get blue where you expect
|
---|
516 | red and vice versa (you'll not notice the problem if you use shades of
|
---|
517 | gray, green, or magenta). You should port your code to use the
|
---|
518 | creator function <a href="qcolor.html#qRgb">qRgb</a>(int r,int g,int b) and the
|
---|
519 | access functions <a href="qcolor.html#qRed">qRed</a>(QRgb), <a href="qcolor.html#qBlue">qBlue</a>(QRgb), and <a href="qcolor.html#qGreen">qGreen</a>(QRgb).
|
---|
520 | If you are using the alpha channel, it hasn't moved, but you should use
|
---|
521 | the functions <a href="qcolor.html#qRgba">qRgba</a>(int,int,int,int) and <a href="qcolor.html#qAlpha">qAlpha</a>(QRgb). Note also that
|
---|
522 | <a href="qcolor.html#pixel">QColor::pixel</a>() does <i>not</i> return a QRgb (it never did on all platforms,
|
---|
523 | but your code may have assumed so on your platform) - this may also produce
|
---|
524 | strange color results - use <a href="qcolor.html#rgb">QColor::rgb</a>() if you want a QRgb.
|
---|
525 | <p> <h3><a name="QDataStream">QDataStream</a></h3>
|
---|
526 | <p> <p>The QDatastream serialization format of most Qt classes is changed
|
---|
527 | in Qt 2.x. Use <pre> QDataStream::setVersion( 1 )</pre>
|
---|
528 | to get a
|
---|
529 | datastream object that can read and write Qt 1.x format data streams.
|
---|
530 | <p> <p>If you want to write Qt 1.x format datastreams, note the following
|
---|
531 | compatibility issues:
|
---|
532 | <ul>
|
---|
533 | <li>QString: Qt 1.x has no Unicode support, so strings will be
|
---|
534 | serialized by writing the classic C string returned by <pre>
|
---|
535 | QString::<a href="qstring.html#latin1">latin1</a>().</pre>
|
---|
536 |
|
---|
537 | <li><a href="#QPoint">QPoint & al.</a>: Coordinates will be
|
---|
538 | truncated to the Qt 1.x 16 bit format.
|
---|
539 | </ul>
|
---|
540 | <p> <h3><a name="QWidget">QWidget</a></h3>
|
---|
541 | <p> <h4>QWidget::recreate()</h4>
|
---|
542 | <p>
|
---|
543 | This function is now called <a href="qwidget.html#reparent">reparent()</a>.
|
---|
544 | <p> <h4>QWidget::setAcceptFocus(bool)</h4>
|
---|
545 | <p>
|
---|
546 | This function is removed.
|
---|
547 | Calls like QWidget::setAcceptFocus(TRUE) should be replaced by
|
---|
548 | <pre> QWidget::setFocusPolicy(StrongFocus)</pre>
|
---|
549 | , and
|
---|
550 | calls like QWidget::setAcceptFocus(FALSE) should be replaced by
|
---|
551 | <pre> QWidget::setFocusPolicy(NoFocus)</pre>
|
---|
552 | .
|
---|
553 | Additional policies are TabFocus and ClickFocus.
|
---|
554 | <p> <h4>QWidget::paintEvent()</h4>
|
---|
555 | <p>
|
---|
556 | paintEvent(0) is not permitted - subclasses need not check for
|
---|
557 | a null event, and might crash.
|
---|
558 | Never pass 0 as the argument to paintEvent(). You probably
|
---|
559 | just want repaint() or update() instead.
|
---|
560 | <p>
|
---|
561 | When processing a paintEvent, painting is only permitted within
|
---|
562 | the update region specified in the event. Any painting outside will be
|
---|
563 | clipped away. This shouldn't break any code (it was always like this
|
---|
564 | on MS-Windows) but makes many explicit calls to
|
---|
565 | <a href="qpainter.html#setClipRegion">QPainter::setClipRegion</a>() superfluous. Apart from the improved
|
---|
566 | consistency, the change is likely to reduce flicker and to make Qt
|
---|
567 | event slightly faster.
|
---|
568 | <p> <h3><a name="QIODevice">QIODevice</a></h3>
|
---|
569 | <p>
|
---|
570 | The protected member QIODevice::index is renamed to QIODevice::ioIndex
|
---|
571 | to avoid warnings and to allow compilation with bad C libraries that
|
---|
572 | #define index to strchr. If you have made a subclass of <a href="qiodevice.html">QIODevice</a>,
|
---|
573 | check every occurrence of the string "index" in the implementation, since
|
---|
574 | a compiler will not always catch cases like <pre>(uint)index</pre>
|
---|
575 |
|
---|
576 | that need to be changed.
|
---|
577 | <p> <h3><a name="QLabel">QLabel</a></h3>
|
---|
578 | <p> <h4><pre> QLabel::setMargin()</pre>
|
---|
579 | </h4>
|
---|
580 | <p>
|
---|
581 | <pre> QLabel::setMargin()</pre>
|
---|
582 | and<pre> QLabel::margin()</pre>
|
---|
583 |
|
---|
584 | have been renamed to <pre> QLabel::setIndent()</pre>
|
---|
585 | and
|
---|
586 | <pre> QLabel::indent()</pre>
|
---|
587 | , respectively. This was done to avoid
|
---|
588 | collision with <a href="qframe.html#setMargin">QFrame::setMargin</a>(), which is now virtual.
|
---|
589 | <p> <h4><pre> QLabel::setMovie()</pre>
|
---|
590 | </h4>
|
---|
591 | <p>
|
---|
592 | Previously, setting a movie on a label cleared the value of text().
|
---|
593 | Now it doesn't. If you somehow used <tt>QLabel::text()</tt>
|
---|
594 | to detect if a
|
---|
595 | movie was set, you might have trouble. This is unlikely.
|
---|
596 | <p> <h3><a name="QDialog">QDialog</a></h3>
|
---|
597 | <p> <p> The semantics of the parent pointer changed for modeless dialogs:
|
---|
598 | In Qt-2.x, dialogs are always top level windows. The parent, however,
|
---|
599 | takes the ownership of the dialog, i.e. it will delete the dialog at
|
---|
600 | destruction if it has not been explicitly deleted
|
---|
601 | already. Furthermore, the window system will be able to tell that both
|
---|
602 | the dialog and the parent belong together. Some X11 window managers
|
---|
603 | will for instance provide a common taskbar entry in that case.
|
---|
604 | <p> <p>
|
---|
605 | If the dialog belongs to a top level main window
|
---|
606 | of your application, pass this main window as parent to the dialog's
|
---|
607 | constructor. Old code (with 0 pointer) will still run. Old code that
|
---|
608 | included QDialogs as child widgets will no longer work (it never really did).
|
---|
609 | If you think you might be doing this, put a breakpoint in
|
---|
610 | <a href="qdialog.html#QDialog">QDialog::QDialog</a>() conditional on parent not being 0.
|
---|
611 | <p> <h3><a name="QStrList">QStrList</a></h3>
|
---|
612 | <p> Many methods that took a <a href="qstrlist.html">QStrList</a> can now instead take a <a href="qstringlist.html">QStringList</a>,
|
---|
613 | which is a real list of <a href="qstring.html">QString</a> values.
|
---|
614 | <p> To use QStringList rather than QStrList, change loops that look like this:
|
---|
615 | <pre>
|
---|
616 | <a href="qstrlist.html">QStrList</a> list = ...;
|
---|
617 | const char* s;
|
---|
618 | for ( s = list.<a href="qptrlist.html#first">first</a>(); s; s = list.<a href="qptrlist.html#next">next</a>() ) {
|
---|
619 | process(s);
|
---|
620 | }
|
---|
621 | </pre>
|
---|
622 |
|
---|
623 | to be like this:
|
---|
624 | <pre>
|
---|
625 | <a href="qstringlist.html">QStringList</a> list = ...;
|
---|
626 | QStringList::ConstIterator i;
|
---|
627 | for ( i = list.<a href="qvaluelist.html#begin">begin</a>(); i != list.<a href="qvaluelist.html#end">end</a>(); ++i ) {
|
---|
628 | process(*i);
|
---|
629 | }
|
---|
630 | </pre>
|
---|
631 |
|
---|
632 | <p> In general, the QStrList functions are less efficient, building a temporary QStringList.
|
---|
633 | <p> The following functions now use QStringList rather than QStrList
|
---|
634 | for return types/parameters.
|
---|
635 | <p> <ul>
|
---|
636 | <li><tt>void <a href="qfiledialog.html#setFilters">QFileDialog::setFilters</a>(const <a href="qstrlist.html">QStrList</a>&)</tt>
|
---|
637 | becomes <tt>void QFileDialog::setFilters(const <a href="qstringlist.html">QStringList</a>&)</tt>
|
---|
638 | <li><tt>QStrList <a href="qfiledialog.html#getOpenFileNames">QFileDialog::getOpenFileNames</a>(...)</tt>
|
---|
639 | becomes <tt>QStringList QFileDialog::getOpenFileNames(...)</tt>
|
---|
640 | <li><tt>bool QUrlDrag::decodeLocalFiles(<a href="qmimesource.html">QMimeSource</a>*, QStrList&)</tt>
|
---|
641 | becomes <tt>bool <a href="quridrag.html#decodeLocalFiles">QUriDrag::decodeLocalFiles</a>(QMimeSource*, QStringList&)</tt>
|
---|
642 | <li><tt>const QStrList *QDir::entryList(...) const</tt>
|
---|
643 | becomes <tt>QStringList <a href="qdir.html#entryList">QDir::entryList</a>(...) const</tt>
|
---|
644 | (note that the return type is no longer a pointer). You may also
|
---|
645 | choose to use encodedEntryList().
|
---|
646 | </ul>
|
---|
647 | <p> The following functions are added:
|
---|
648 | <ul>
|
---|
649 | <li><tt>QComboBox::insertStringList(const QStringList &, int index=-1)</tt>
|
---|
650 | <li><tt>QListBox::insertStringList(const QStringList &,int index=-1)</tt>
|
---|
651 | </ul>
|
---|
652 | <p> The rarely used static function <tt>void
|
---|
653 | QFont::listSubstitutions(<a href="qstrlist.html">QStrList</a>*)</tt> is replaced by <tt>QStringList
|
---|
654 | <a href="qfont.html#substitutions">QFont::substitutions</a>()</tt>.
|
---|
655 | <p> <h3><a name="QLayout">QLayout</a></h3>
|
---|
656 | <p> <p> Calling resize(0,0) or resize(1,1) will no longer work magically.
|
---|
657 | Remove all such calls. The default size of top level widgets will be their
|
---|
658 | <a href="qwidget.html#sizeHint">sizeHint()</a>.
|
---|
659 | <p> <p> The default implementation of <a href="qwidget.html#sizeHint">QWidget::sizeHint</a>() will no longer
|
---|
660 | return just an invalid size; if the widget has a layout, it will return
|
---|
661 | the layout's preferred size.
|
---|
662 | <p> <p> The special maximum MaximumHeight/Width is now QWIDGETSIZE_MAX,
|
---|
663 | not QCOORD_MAX.
|
---|
664 | <p> <p> <a href="qboxlayout.html#addWidget">QBoxLayout::addWidget()</a>
|
---|
665 | now interprets the <em>alignment</em> parameter more aggressively. A
|
---|
666 | non-default alignment now indicates that the widget should not grow to
|
---|
667 | fill the available space, but should be sized according to sizeHint().
|
---|
668 | If a widget is too small, set the alignment to 0. (Zero indicates no
|
---|
669 | alignment, and is the default.)
|
---|
670 | <p> <p> The class QGManager is removed. Subclasses of <a href="qlayout.html">QLayout</a> need to be rewritten
|
---|
671 | to use the new, much simpler <a href="qlayout.html">QLayout API</a>.
|
---|
672 | <p> <p> For typical layouts, all use of
|
---|
673 | <a href="qwidget.html#setMinimumSize">setMinimumSize()</a>
|
---|
674 | and
|
---|
675 | <a href="qwidget.html#setFixedSize">setFixedSize()</a>
|
---|
676 | can be removed.
|
---|
677 | <a href="qlayout.html#activate">activate()</a> is no longer necessary.
|
---|
678 | <p> <p>
|
---|
679 | You might like to look at the <a href="qgrid.html">QGrid</a>, <a href="qvbox.html">QVBox</a>, and <a href="qhbox.html">QHBox</a> widgets - they offer
|
---|
680 | a simple way to build nested widget structures.
|
---|
681 | <p> <h3><a name="QListView">QListView</a></h3>
|
---|
682 | <p> <p>In Qt 1.x mouse events to the viewport where redirected to the
|
---|
683 | event handlers for the listview; in Qt 2.x, this functionality is
|
---|
684 | in <a href="qscrollview.html">QScrollView</a> where mouse (and other position-oriented) events are
|
---|
685 | redirected to viewportMousePressEvent() etc, which in turn translate
|
---|
686 | the event to the coordinate system of the contents and call
|
---|
687 | contentsMousePressEvent() etc, thus providing events in the most
|
---|
688 | convenient coordinate system. If you overrode QListView::MouseButtonPress(),
|
---|
689 | <a href="qwidget.html#mouseDoubleClickEvent">QListView::mouseDoubleClickEvent</a>(), <a href="qwidget.html#mouseMoveEvent">QListView::mouseMoveEvent</a>(), or
|
---|
690 | <a href="qwidget.html#mouseReleaseEvent">QListView::mouseReleaseEvent</a>() you must instead override
|
---|
691 | viewportMousePressEvent(),
|
---|
692 | viewportMouseDoubleClickEvent(), viewportMouseMoveEvent(), or
|
---|
693 | viewportMouseReleaseEvent() respectively. New code will usually override
|
---|
694 | contentsMousePressEvent() etc.
|
---|
695 | <p> <p>The signal <a href="qlistview.html#selectionChanged">QListView::selectionChanged</a>(<a href="qlistviewitem.html">QListViewItem</a> *) can now be
|
---|
696 | emitted with a null pointer as parameter. Programs that use the
|
---|
697 | argument without checking for 0, may crash.
|
---|
698 | <p> <h3><a name="QMultiLineEdit">QMultiLineEdit</a></h3>
|
---|
699 | <p> <p>
|
---|
700 | The protected function
|
---|
701 | <pre> QMultiLineEdit::textWidth(QString*)</pre>
|
---|
702 |
|
---|
703 | changed to
|
---|
704 | <pre> QMultiLineEdit::textWidth(const <a href="qstring.html">QString</a>&)</pre>
|
---|
705 | .
|
---|
706 | This is unlikely to be a problem, and you'll get a compile error
|
---|
707 | if you called it.
|
---|
708 | <p> <h3><a name="QClipboard">QClipboard</a></h3>
|
---|
709 | <p> <p>
|
---|
710 | <pre> QClipboard::pixmap()</pre>
|
---|
711 | now returns a <a href="qpixmap.html">QPixmap</a>, not a QPixmap*.
|
---|
712 | The pixmap
|
---|
713 | will be <a href="qpixmap.html#isNull">null</a> if no pixmap is on the
|
---|
714 | clipboard. <a href="qclipboard.html">QClipboard</a> now offers powerful MIME-based types on the
|
---|
715 | clipboard, just like drag-and-drop (in fact, you can reuse most of your
|
---|
716 | drag-and-drop code with clipboard operations).
|
---|
717 | <p> <h3><a name="QDropSite">QDropSite</a></h3>
|
---|
718 | <p> <P>
|
---|
719 | QDropSite is obsolete. If you simply passed <tt>this</tt>, just remove
|
---|
720 | the inheritance of QDropSite and call
|
---|
721 | <a href="qwidget.html#setAcceptDrops">setAcceptDrops(TRUE)</a> in the class
|
---|
722 | constructor.
|
---|
723 | If you passed something other than <tt>this</tt>,
|
---|
724 | your code will not work. A common case is passing
|
---|
725 | the
|
---|
726 | <a href="qscrollview.html#viewport">viewport()</a> of a <a href="qlistview.html">QListView</a>,
|
---|
727 | in which case,
|
---|
728 | override the
|
---|
729 | <a href="qscrollview.html#contentsDragMoveEvent">contentsDragMoveEvent()</a>,
|
---|
730 | etc.
|
---|
731 | functions rather than QListView's dragMoveEvent() etc. For other
|
---|
732 | cases, you will need to use an event filter to act on the drag/drop events
|
---|
733 | of another widget (as is the usual way to intercept foreign events).
|
---|
734 | <p> <h3><a name="QScrollView">QScrollView</a></h3>
|
---|
735 | <p> The parameters in the signal
|
---|
736 | <a href="qscrollview.html#contentsMoving">contentsMoving(int,int)</a>
|
---|
737 | are now positive rather than negative values, coinciding with
|
---|
738 | <a href="qscrollview.html#setContentsPos">setContentsPos()</a>. Search for
|
---|
739 | connections you make to this signal, and either change the slot they are
|
---|
740 | connected to such that it also expects positive rather than negative
|
---|
741 | values, or introduce an intermediate slot and signal that negates them.
|
---|
742 | <p> If you used drag and drop with <a href="qscrollview.html">QScrollView</a>, you may experience the problem
|
---|
743 | described for <a href="#QDropSite">QDropSite</a>.
|
---|
744 | <p> <h3><a name="QTextStream">QTextStream</a></h3>
|
---|
745 | <p> <p>
|
---|
746 | <pre> operator<<(QTextStream&, QChar&)</pre>
|
---|
747 | does not skip whitespace.
|
---|
748 | <pre> operator<<(QTextStream&, char&)</pre>
|
---|
749 | does,
|
---|
750 | as was the case with Qt 1.x. This is for backward compatibility.
|
---|
751 | <p> <h3><a name="QUriDrag">QUriDrag</a></h3>
|
---|
752 | <p> The class QUrlDrag is renamed to <a href="quridrag.html">QUriDrag</a>, and the API has been
|
---|
753 | broadened to include additional conversion routines, including
|
---|
754 | conversions to Unicode filenames (see the class documentation
|
---|
755 | for details). Note that in Qt 1.x
|
---|
756 | the QUrlDrag class used the non-standard MIME type "url/url",
|
---|
757 | while QUriDrag uses the standardized "text/uri-list" type. Other
|
---|
758 | identifiers affected by the Url to Uri change are
|
---|
759 | QUrlDrag::setUrls() and QUrlDrag::urlToLocalFile().
|
---|
760 | <p> <h3><a name="QPainter">QPainter</a></h3>
|
---|
761 | <p> <p> The GrayText painter flag has been removed. Use
|
---|
762 | <a href="qpainter.html#setPen">setPen( palette().disabled().foreground() )</a>
|
---|
763 | instead.
|
---|
764 | <p> <p> The RasterOp enum
|
---|
765 | (CopyROP,
|
---|
766 | OrROP,
|
---|
767 | XorROP,
|
---|
768 | NotAndROP,
|
---|
769 | EraseROP,
|
---|
770 | NotCopyROP,
|
---|
771 | NotOrROP,
|
---|
772 | NotXorROP,
|
---|
773 | AndROP, NotEraseROP,
|
---|
774 | NotROP,
|
---|
775 | ClearROP,
|
---|
776 | SetROP,
|
---|
777 | NopROP,
|
---|
778 | AndNotROP,
|
---|
779 | OrNotROP,
|
---|
780 | NandROP,
|
---|
781 | NorROP, LastROP)
|
---|
782 | is now part of the Qt namespace class, so if you
|
---|
783 | use it outside a member function, you'll need to prefix with Qt::.
|
---|
784 | <p> <h3><a name="QPicture">QPicture</a></h3>
|
---|
785 | <p> <p>The binary storage format of <a href="qpicture.html">QPicture</a> is changed, but the Qt 2.x
|
---|
786 | QPicture class can both read and write Qt 1.x format QPictures. No
|
---|
787 | special handling is required for reading; QPicture will automatically
|
---|
788 | detect the version number. In order to write a Qt 1.x format QPicture,
|
---|
789 | set the formatVersion parameter to 1 in the QPicture constructor.
|
---|
790 | <p> <p>For writing Qt 1.x format QPictures, the compatibility issues of <a
|
---|
791 | href="#QDataStream">QDataStream</a> applies.
|
---|
792 | <p> <p>It is safe to try to read a QPicture file generated with Qt 2.x
|
---|
793 | (without formatVersion set to 1) with a program compiled with Qt
|
---|
794 | 1.x. The program will not crash, it will just issue the warning
|
---|
795 | "QPicture::play: Incompatible version 2.x" and refuse to load the
|
---|
796 | picture.
|
---|
797 | <p> <h3><a name="QPoint">QPoint, <a href="qpointarray.html">QPointArray</a>, <a href="qsize.html">QSize</a> and <a href="qrect.html">QRect</a></a></h3>
|
---|
798 | <p> <p>The basic coordinate datatype in these classes, QCOORD, is now 32
|
---|
799 | bit (int) instead of a 16 bit (short). The const values QCOORD_MIN and
|
---|
800 | QCOORD_MAX have changed accordingly.
|
---|
801 | <p> <p>QPointArray is now actually, not only seemingly, a QArray of <a href="qpoint.html">QPoint</a>
|
---|
802 | objects. The semi-internal workaround classes QPointData and QPointVal
|
---|
803 | are removed since they are no longer needed; QPoint is used directly
|
---|
804 | instead. The function <pre> QPointArray::shortPoints()</pre>
|
---|
805 |
|
---|
806 | provides the point array converted to short (16bit) coordinates for
|
---|
807 | use with external functions that demand that format.
|
---|
808 | <p> <h3><a name="QImage">QImage</a></h3>
|
---|
809 | <p> <a href="qimage.html">QImage</a> uses QRgb for the colors - see <a href="#QRgb">the changes to that</a>.
|
---|
810 | <p> <h3><a name="QPixmap">QPixmap</a></h3>
|
---|
811 | <p> <pre> QPixmap::convertToImage()</pre>
|
---|
812 | with bitmaps now guarantees that color0 pixels
|
---|
813 | become color(0) in the resulting QImage. If you worked around the lack of
|
---|
814 | this, you may be able to simplify your code. If you made assumptions
|
---|
815 | about the previous undefined behavior, the symptom will be inverted
|
---|
816 | bitmaps (eg. "inside-out" masks).
|
---|
817 | <p> <p>
|
---|
818 | <pre> QPixmap::optimize(TRUE)</pre>
|
---|
819 |
|
---|
820 | is replaced by
|
---|
821 | <pre> QPixmap::setOptimization(QPixmap::NormalOptim)</pre>
|
---|
822 |
|
---|
823 | or
|
---|
824 | <pre> QPixmap::setOptimization(QPixmap::BestOptim)</pre>
|
---|
825 |
|
---|
826 | - see the documentation
|
---|
827 | to choose which is best for your application. NormalOptim is most like
|
---|
828 | the Qt 1.x "TRUE" optimization.
|
---|
829 | <p> <h3><a name="QMenuData">QMenuData / <a href="qpopupmenu.html">QPopupMenu</a></a></h3>
|
---|
830 | <p> In Qt 1.x, new menu items were assigned either an application-wide
|
---|
831 | unique identifier or an identifier equal to the index of the item, depending on the
|
---|
832 | <a href="qmenudata.html#insertItem">insertItem(...)</a> function used.
|
---|
833 | In Qt 2.x this confusing
|
---|
834 | situation has been cleaned up: generated identifiers are always
|
---|
835 | unique across the entire application.
|
---|
836 | <p> If your code depends on generated ids
|
---|
837 | being equal to the item's index, a quick fix is to use
|
---|
838 | <pre> QMenuData::indexOf(int id)</pre>
|
---|
839 |
|
---|
840 | in the handling function instead. You may alternatively pass
|
---|
841 | <pre> QMenuData::count()</pre>
|
---|
842 |
|
---|
843 | as identifier when you insert the items.
|
---|
844 | <p> Furthermore, QPopupMenus can (and should!) be created with a parent
|
---|
845 | widget now, for example the main window that is used to display the
|
---|
846 | popup. This way, the popup will automatically be destroyed together
|
---|
847 | with its main window. Otherwise you'll have to take care of the
|
---|
848 | ownership manually.
|
---|
849 | <p> QPopupMenus are also reusable in 2.x. They may occur in different
|
---|
850 | locations within one menu structure or be used as both a menubar
|
---|
851 | drop-down and as a context popup-menu. This should make it possible to
|
---|
852 | significantly simplify many applications.
|
---|
853 | <p> Last but not least, <a href="qpopupmenu.html">QPopupMenu</a> no longer inherits QTableView. Instead,
|
---|
854 | it directly inherits <a href="qframe.html">QFrame</a>.
|
---|
855 | <p> <h3><a name="QValidator">QValidator (<a href="qlineedit.html">QLineEdit</a>, <a href="qcombobox.html">QComboBox</a>, <a href="qspinbox.html">QSpinBox</a>) </a></h3>
|
---|
856 | <p> <pre> QValidator::validate(...)</pre>
|
---|
857 |
|
---|
858 | and
|
---|
859 | <pre> QValidator::fixup( <a href="qstring.html">QString</a> & )</pre>
|
---|
860 |
|
---|
861 | are now const
|
---|
862 | functions. If your subclass reimplements validate() as a
|
---|
863 | non-const function,
|
---|
864 | you will get a compile error (validate was pure virtual).
|
---|
865 | <p> In QLineEdit, QComboBox, and QSpinBox,
|
---|
866 | setValidator(...) now takes a const pointer to a <a href="qvalidator.html">QValidator</a>, and
|
---|
867 | validator() returns a const pointer. This change highlights the fact
|
---|
868 | that the widgets do not take the ownership of the validator (a validator is
|
---|
869 | a <a href="qobject.html">QObject</a> on its own, with its own parent - you can easily set the same validator
|
---|
870 | object on many different widgets), so changing the state of
|
---|
871 | such an object or deleting it is very likely a bug.
|
---|
872 | <p> <h3><a name="QFile">QFile, <a href="qfileinfo.html">QFileInfo</a>, <a href="qdir.html">QDir</a></a></h3>
|
---|
873 | <p> File and directory names are now always Unicode strings (ie. <a href="qstring.html">QString</a>). If you used QString
|
---|
874 | in the past for the simplicity it offers, you'll probably have little consequence. However,
|
---|
875 | if you pass filenames to system functions rather than using Qt functions (eg. if you use the
|
---|
876 | Unix <tt>unlink()</tt> function rather than <tt>QFile::remove()</tt>, your code will probably
|
---|
877 | only work for Latin1 locales (eg. Western Europe, the U.S.). To ensure your code will support
|
---|
878 | filenames in other locales, either use the Qt functions, or convert the filenames via
|
---|
879 | <pre> QFile::encodeFilename()</pre>
|
---|
880 | and <pre> QFile::decodeFilename()</pre>
|
---|
881 | - but do it
|
---|
882 | <em>just</em> as you call the system function - code that mixes encoded and unencoded filenames
|
---|
883 | is very error prone. See the comments in QString, such as regarding QT_NO_ASCII_CAST that
|
---|
884 | can help find potential problems.
|
---|
885 | <p> <h3><a name="QFontMetrics">QFontMetrics</a></h3>
|
---|
886 | <p> boundingRect(char) is replaced by
|
---|
887 | boundingRect(<a href="qchar.html">QChar</a>), but since
|
---|
888 | char auto-converts to QChar, you're not likely to run into problems
|
---|
889 | with this.
|
---|
890 | <p> <h3><a name="QWindow">QWindow</a></h3>
|
---|
891 | <p> This class (which was just <a href="qwidget.html">QWidget</a> under a different name) has been
|
---|
892 | removed. If you used it, do a global search-and-replace of the word
|
---|
893 | "QWindow" with "QWidget".
|
---|
894 | <p> <h3><a name="QEvent">QEvent</a></h3>
|
---|
895 | <p> <p> The global #define macros in qevent.h have been replaced by an
|
---|
896 | enum in <a href="qevent.html">QEvent</a>. Use e.g. QEvent::Paint instead of Event_Paint. Same
|
---|
897 | for all of:
|
---|
898 | Event_None,
|
---|
899 | Event_Timer,
|
---|
900 | Event_MouseButtonPress,
|
---|
901 | Event_MouseButtonRelease,
|
---|
902 | Event_MouseButtonDblClick,
|
---|
903 | Event_MouseMove,
|
---|
904 | Event_KeyPress,
|
---|
905 | Event_KeyRelease,
|
---|
906 | Event_FocusIn,
|
---|
907 | Event_FocusOut,
|
---|
908 | Event_Enter,
|
---|
909 | Event_Leave,
|
---|
910 | Event_Paint,
|
---|
911 | Event_Move,
|
---|
912 | Event_Resize,
|
---|
913 | Event_Create,
|
---|
914 | Event_Destroy,
|
---|
915 | Event_Show,
|
---|
916 | Event_Hide,
|
---|
917 | Event_Close,
|
---|
918 | Event_Quit,
|
---|
919 | Event_Accel,
|
---|
920 | Event_Clipboard,
|
---|
921 | Event_SockAct,
|
---|
922 | Event_DragEnter,
|
---|
923 | Event_DragMove,
|
---|
924 | Event_DragLeave,
|
---|
925 | Event_Drop,
|
---|
926 | Event_DragResponse,
|
---|
927 | Event_ChildInserted,
|
---|
928 | Event_ChildRemoved,
|
---|
929 | Event_LayoutHint,
|
---|
930 | Event_ActivateControl,
|
---|
931 | Event_DeactivateControl,
|
---|
932 | and
|
---|
933 | Event_User.
|
---|
934 | <p> <p> The Q_*_EVENT macros in qevent.h have been deleted. Use an
|
---|
935 | explicit cast instead. The macros were:
|
---|
936 | Q_TIMER_EVENT,
|
---|
937 | Q_MOUSE_EVENT,
|
---|
938 | Q_KEY_EVENT,
|
---|
939 | Q_FOCUS_EVENT,
|
---|
940 | Q_PAINT_EVENT,
|
---|
941 | Q_MOVE_EVENT,
|
---|
942 | Q_RESIZE_EVENT,
|
---|
943 | Q_CLOSE_EVENT,
|
---|
944 | Q_SHOW_EVENT,
|
---|
945 | Q_HIDE_EVENT,
|
---|
946 | and
|
---|
947 | Q_CUSTOM_EVENT.
|
---|
948 | <p> <p> QChildEvents are now sent for all QObjects, not just QWidgets.
|
---|
949 | You may need to add extra checking if you use a <a href="qchildevent.html">QChildEvent</a> without
|
---|
950 | much testing of its values.
|
---|
951 | <p> <h3>All the removed functions</h3>
|
---|
952 | <p> All <a href="removed20.html">these functions</a> have been removed in
|
---|
953 | Qt 2.x. Most are simply cases where "const char*" has changed to
|
---|
954 | "const <a href="qstring.html">QString</a>&", or when an enumeration type has moved into the Qt::
|
---|
955 | namespace (which, technically, is a new name, but your code will
|
---|
956 | compile just the same anyway). This list is provided for completeness.
|
---|
957 | <p>
|
---|
958 | <!-- eof -->
|
---|
959 | <p><address><hr><div align=center>
|
---|
960 | <table width=100% cellspacing=0 border=0><tr>
|
---|
961 | <td>Copyright © 2007
|
---|
962 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
963 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
964 | </table></div></address></body>
|
---|
965 | </html>
|
---|