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-3.html

179 lines
8.5 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:334 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Using Qt Standard Dialogs</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>Using Qt Standard Dialogs</h1>
[ <a href="motif-walkthrough-2.html">Previous: Preparing to Migrate the User Interface</a> ]
[ <a href="motif-walkthrough.html">Home</a> ]
[ <a href="motif-walkthrough-4.html">Next: Using Custom QDialogs</a> ]
<p> We start by using two of the <a href="dialogs.html">Qt Standard
Dialogs</a>: <a href="qfiledialog.html">QFileDialog</a> and <a href="qmessagebox.html">QMessageBox</a>. Both of these classes
provide useful static convenience functions.
<p> <center><table cellpadding="4" cellspacing="2" border="0">
<tr bgcolor="#f0f0f0"> <td valign="top">QFileDialog::getOpenFileName() <td valign="top">replacement for the <em>Open</em> dialog
<tr bgcolor="#d0d0d0"> <td valign="top">QFileDialog::getSaveFileName() <td valign="top">replacement for the <em>Save As</em> dialog
<tr bgcolor="#f0f0f0"> <td valign="top">QMessageBox::information() <td valign="top">replacement for <em>Page Delete</em> dialog
<tr bgcolor="#d0d0d0"> <td valign="top">QMessageBox::warning() <td valign="top">replacement for <em>IO Error</em> dialog.
</table></center>
<p> Each of these functions takes a <em>QWidget *parent</em> argument. If we
pass zero as the <em>parent</em> argument, then we will have dialogs that
are centered on the screen, instead of being centered over our main
window. We can have <a href="qmotifwidget.html">QMotifWidget</a> create our <tt>XmMainWindow</tt>, and we
can then use this class as the parent for both <a href="motif-extension.html#Motif">Motif</a> dialogs and Qt
dialogs.
<p> We need to include the appropriate headers for QMotifWidget and
<a href="qfiledialog.html">QFileDialog</a> in <tt>todo.cpp</tt>.
<p>
<pre></pre>
<p> Next, we make a few modifications to how the application is
initialized. We could initialize Xt/Motif and create the <tt>XtAppContext</tt> ourselves, but <a href="qmotif.html">QMotif</a> can do this for us.
We also let <a href="qapplication.html">QApplication</a> open the connection to the X server. Next,
we create a QMotifWidget, passing <tt>xmMainWindowWidgetClass</tt> as the <em>widgetclass</em> argument. We can now use the <a href="qmotifwidget.html#motifWidget">QMotifWidget::motifWidget</a>()
function to access the Motif widget. The shell widget is created
automatically by QMotifWidget. We use <tt>XtParent()</tt> to access it.
The top-level window is now a QMotifWidget, which means we can use it
as the parent for the Qt Standard Dialogs.
<p> <pre></pre>
<p> <h2> Replacing the <em>Open</em> and <em>Save As</em> Dialogs
</h2>
<a name="1"></a><p> First, we completely remove all use of the existing Motif file
selection dialog. We remove the <tt>Xm/FileSB.h</tt> include, the global <tt>file_dialog</tt> variable, and the code to create the dialog. We also
remove the <tt>PresentFDialog()</tt> callback function. None of this code
is needed to use <a href="qfiledialog.html">QFileDialog</a>.
<p> After removing the <tt>PresentFDialog()</tt> callback function, we need to
make <em>Open</em> and <em>Save As</em> popup-menu callbacks call the <tt>Open()</tt>
and <tt>Save()</tt> functions.
<p> First we must change the declaration of these two functions.
<p>
<p> <pre></pre>
<p> We also change the arguments to the callbacks. We pass the top-level
<a href="qmotifwidget.html">QMotifWidget</a> as the <tt>client_data</tt> to these functions, since we will
be using it as the parent for the QFileDialog.
<p> <pre></pre>
<p> <pre>
...
</pre>
<p> <pre></pre>
<p> Next, we modify the <tt>Save()</tt> function to use
<a href="qfiledialog.html#getSaveFileName">QFileDialog::getSaveFileName</a>().
<p> <pre></pre>
<p> ... and the <tt>Open()</tt> function to use <a href="qfiledialog.html#getOpenFileName">QFileDialog::getOpenFileName</a>().
<p> <pre></pre>
<p> After we build the project, the application runs and operates as
expected. The difference is that the <em>Open</em> and <em>Save As</em> dialogs
now use <a href="qfiledialog.html">QFileDialog</a>.
<p> <h2> Replacing the <em>Page Delete</em> and <em>IO Error</em> Dialogs
</h2>
<a name="2"></a><p> The <em>Page Delete</em> dialog is created and used in <tt>actions.c</tt>. We
need to migrate this file to C++. We rename it to <tt>actions.cpp</tt>,
modify the project file and regenerate the <tt>Makefile</tt>.
<p> The changes required to make <tt>actions.cpp</tt> compile are minimal. We
need to wrap more C header files and global variables in an <tt>extern "C"</tt> block.
<p>
<p> <pre></pre>
<p> We need to forward declare the <tt>NewPage()</tt>, <tt>DeletePage()</tt>, <tt>EditPage()</tt> and <tt>SaveIt()</tt> functions so that the compiler generates
the correct symbols for these functions.
<p> <pre></pre>
<p> We need to fix a single invalid pointer cast.
<p> <pre></pre>
<p> And we need to change the variable named <em>new</em> to <em>newstr</em> in the <tt>Trim()</tt> function.
<p> We can now change the <tt>DeletePage()</tt> function to use
<a href="qmessagebox.html#information">QMessageBox::information</a>().
<p> First, we need to make sure we include the proper header for
<a href="qmessagebox.html">QMessageBox</a>.
<p>
<pre></pre>
<p> The code for <tt>DeletePage()</tt> looks like this:
<p> <pre></pre>
<p> At this point in the code, the page should be deleted. The code to do
this is in the <tt>DoDeletePage()</tt> function. We move the contents of <tt>DoDeletePage()</tt> to this point and remove the <tt>DoDeletePage()</tt> function
completely.
<p> Next, we change <tt>todo.cpp</tt> to pass the top-level <a href="qmotifwidget.html">QMotifWidget</a> as the
<tt>client_data</tt> tot he <tt>DeletePage()</tt> function.
<p>
<p> <pre></pre>
<p> The <em>IO Error</em> dialog is created and used in <tt>io.c</tt>. We need to
migrate this file to C++. We rename it to <tt>io.cpp</tt>, modify the
project file and regenerate the <tt>Makefile</tt>.
<p> The changes required to make <tt>io.cpp</tt> compile are minimal. We need
to wrap more C header files and global variables in an <tt>extern "C"</tt>
block.
<p>
<p> <pre></pre>
<p> We need to forward declare the <tt>ReadDB()</tt> and <tt>SaveDB()</tt> functions
so that the compiler generates the correct symbols for these
functions.
<p> <pre></pre>
<p> The <tt>ParseNewLines()</tt> function needs to be converted to proper C++.
<p> <pre></pre>
<p> The <tt>PrintWithNewLines()</tt> function also needs to be converted to proper
C++.
<p> <pre></pre>
<p> We can now change the <tt>ReadDB()</tt> and <tt>SaveDB()</tt> functions to use
<a href="qmessagebox.html#warning">QMessageBox::warning</a>().
<p> First, we need to make sure we include the proper header for <a href="qmessagebox.html">QMessageBox</a>.
<p>
<pre></pre>
<p> The code for <tt>ReadDB()</tt> looks like this:
<p> <pre></pre><pre>
...
</pre>
<p> The code for <tt>SaveDB()</tt> looks like this:
<p> <pre></pre><pre>
...
</pre>
<p> After we build the project, the application runs and operates as
expected. The difference is that the <em>Page Delete</em> and <em>IO Error</em> dialogs now use QMessageBox.
<p> [ <a href="motif-walkthrough-2.html">Previous: Preparing to Migrate the User Interface</a> ]
[ <a href="motif-walkthrough.html">Home</a> ]
[ <a href="motif-walkthrough-4.html">Next: Using Custom QDialogs</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>