[190] | 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/extensions/motif/doc/walkthrough.doc:1579 -->
|
---|
| 3 | <html>
|
---|
| 4 | <head>
|
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
| 6 | <title>Continuing Development</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>Continuing Development</h1>
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | [ <a href="motif-walkthrough-9.html">Previous: Replacing the Print Dialog</a> ]
|
---|
| 37 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
| 38 | <p> We have not quite finished with the migration to Qt, even though our
|
---|
| 39 | project does not use <a href="motif-extension.html#Motif">Motif</a> any more. Qt provides many useful features
|
---|
| 40 | that we can begin using immediately. Some of the most interesting
|
---|
| 41 | ones are presented below as a guide for where to start extending your
|
---|
| 42 | existing projects.
|
---|
| 43 | <p> <h2> Using Unicode
|
---|
| 44 | </h2>
|
---|
| 45 | <a name="1"></a><p> Support for <a href="i18n.html">internationalization</a> is very easy
|
---|
| 46 | with Qt. Using <a href="qstring.html">QString</a> instead of <tt>char*</tt> for storing text gives
|
---|
| 47 | us support for most of the written languages around the world. Our <tt>Page</tt> and <tt>Options</tt> structs look much simpler now.
|
---|
| 48 | <p>
|
---|
| 49 |
|
---|
| 50 | <p> <pre></pre>
|
---|
| 51 | <p> <pre></pre>
|
---|
| 52 | <p> All functions that use the <tt>Page</tt> and <tt>Options</tt> structs need to be
|
---|
| 53 | updated to use QString properly. Since QString is also an <a href="shclass.html#implicitly-shared">implicitly shared</a> class, we no longer have to do any memory management with our
|
---|
| 54 | strings. We can remove all occurences of the <a href="qcstring.html#qstrdup">qstrdup</a>() function,
|
---|
| 55 | and we never need to use <em>new</em> or <em>delete</em> when done with a string.
|
---|
| 56 | QString will allocate and delete data when needed.
|
---|
| 57 | <p> Here are the <tt>MainWindow::fileOpen()</tt> and <tt>MainWindow::pageChange()</tt>
|
---|
| 58 | functions from <tt>mainwindow.ui.h</tt>. Notice that the code no longer
|
---|
| 59 | uses <em>delete</em> or <a href="qcstring.html#qstrdup">qstrdup</a>() when storing text.
|
---|
| 60 | <p>
|
---|
| 61 |
|
---|
| 62 | <p> <pre></pre>
|
---|
| 63 | <p> <pre>
|
---|
| 64 | ...
|
---|
| 65 | </pre>
|
---|
| 66 |
|
---|
| 67 | <p> <pre></pre>
|
---|
| 68 | <p> Almost all of the functions in our application are affected by this
|
---|
| 69 | change. In most cases, we end up removing more code than we are
|
---|
| 70 | adding. To keep the size of this walkthrough reasonable, we've only
|
---|
| 71 | shown a small portion of the required changes, since the changes are
|
---|
| 72 | very similar to those shown above.
|
---|
| 73 | <p> <h2> Writing Platform-Independent Code
|
---|
| 74 | </h2>
|
---|
| 75 | <a name="2"></a><p> Qt provides many <a href="io.html">input and output</a> classes. We
|
---|
| 76 | can use these in <tt>MainWindow::readDB()</tt> and <tt>MainWindow::saveDB()</tt>.
|
---|
| 77 | Currently, these functions use functions only found on UNIX machines.
|
---|
| 78 | Using <a href="qfile.html">QFile</a> and <a href="qtextstream.html">QTextStream</a> removes this dependency on UNIX, and we can
|
---|
| 79 | begin building and testing our application on Microsoft Windows and
|
---|
| 80 | Apple Mac OS X.
|
---|
| 81 | <p> The platform-independent versions of the <tt>MainWindow::readDB()</tt> and
|
---|
| 82 | <tt>MainWindow::saveDB()</tt> functions can be found in the <tt>io.cpp</tt> file.
|
---|
| 83 | <p> <h2> Designing a Modern User Interface
|
---|
| 84 | </h2>
|
---|
| 85 | <a name="3"></a><p> Since we used the <em>Qt Designer</em> to design the <em>Main Window</em>
|
---|
| 86 | widget, we can extend the interface easily. We can use some of the
|
---|
| 87 | more advanced features of <a href="qmainwindow.html">QMainWindow</a>, which includes dockable
|
---|
| 88 | toolbars. Adding these is simple with the <em>Qt Designer</em>. The
|
---|
| 89 | final version of our project includes a toolbar, which provides quick
|
---|
| 90 | access to the <em>Open</em>, <em>Save</em>, <em>Print</em>, <em>New Page</em> and <em>Delete to Trash</em> actions.
|
---|
| 91 | <p> The possibilities are endless. An <em>Edit</em> menu, with the common <em>Cut</em>, <em>Copy</em> and <em>Paste</em> actions, could be added in a relatively
|
---|
| 92 | short period of time. As our project expands to other platforms, we
|
---|
| 93 | could add menus and dialogs that allow us synchronize todo lists
|
---|
| 94 | between a normal desktop computer and a handheld device running with
|
---|
| 95 | Qt/Embedded.
|
---|
| 96 | <p> [ <a href="motif-walkthrough-9.html">Previous: Replacing the Print Dialog</a> ]
|
---|
| 97 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
| 98 | <p>
|
---|
| 99 | <!-- eof -->
|
---|
| 100 | <p><address><hr><div align=center>
|
---|
| 101 | <table width=100% cellspacing=0 border=0><tr>
|
---|
| 102 | <td>Copyright © 2007
|
---|
| 103 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
| 104 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
| 105 | </table></div></address></body>
|
---|
| 106 | </html>
|
---|