You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qt3/doc/html/motif-walkthrough-1.html

99 lines
4.2 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/extensions/motif/doc/walkthrough.doc:147 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Getting Started</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Getting Started</h1>
[ <a href="motif-walkthrough.html">Home</a> ]
[ <a href="motif-walkthrough-2.html">Next: Preparing to Migrate the User Interface</a> ]
<p> <h2> Starting with <a href="qmotif.html">QMotif</a> and <a href="qapplication.html">QApplication</a>
</h2>
<a name="1"></a><p> To be able to use Qt, we need to create a QApplication object. The
QApplication class controls all the event delivery and display
management for all other Qt objects and widgets. We need to use the
QMotif class from the <em>Qt <a href="motif-extension.html#Motif">Motif</a> Extension</em> to allow QApplication
and the <tt>XtAppContext</tt> to coexist.
<p> The QApplication object must be created in the <tt>main()</tt> function.
We will need to modify <tt>todo.c</tt> to compile with a C++ compiler, so we
rename <tt>todo.c</tt> to <tt>todo.cpp</tt>.
<p> Next, we add the appropriate includes for the QMotif and QApplication
classes.
<p>
<pre></pre>
<p> Next, we create the QMotif and QApplication objects. We create QMotif
with a foreign <tt>XtAppContext</tt>, and we create QApplication with a
foreign <tt>Display</tt>.
<p> <pre></pre>
<p> The next change is not yet necessary, but it is included to show that
the <em>Qt Motif Extension</em> provides a complete integration.
Normally, a Motif based program would use the <tt>XtAppMainLoop()</tt>
function to run the application's event loop. This is still possible,
but since we are migrating to the Qt toolkit, we prefer to use the
<a href="qapplication.html#exec">QApplication::exec</a>() function for running the event loop.
<p> <pre></pre>
<p> Since we renamed <tt>todo.c</tt> to <tt>todo.cpp</tt>, we must change the
project file and rerun <em>qmake</em> to regenerate our <tt>Makefile</tt>. When we
build our project, there are compile and link errors: we will fix
these in the following section.
<p> <h2> Migrating to C++
</h2>
<a name="2"></a><p> We need to convert the code in this file to proper C++ code.
Fortunately, the changes are not too large. Most files included from
existing C projects are not C++ compatible, so we make them compatible
by wrapping them in an <tt>extern "C"</tt> block.
<p>
<p> <pre></pre>
<p> Global C functions that are forward declared must also be wrapped into
an <tt>extern "C"</tt> block.
<p> <pre></pre>
<p> The <tt>manageCB()</tt> function needs to be converted to proper C++.
<p> <pre></pre>
<p> And we need to fix two invalid casts. One is in the <tt>Save()</tt> function.
<p> <pre></pre>
<p> The other invalid cast is in the <tt>Open()</tt> function.
<p> <pre></pre>
<p> After these changes, the project compiles and links, and the
application runs and operates correctly.
<p> [ <a href="motif-walkthrough.html">Home</a> ]
[ <a href="motif-walkthrough-2.html">Next: Preparing to Migrate the User Interface</a> ]
<p>
<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>