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:334 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Using Qt Standard Dialogs</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>Using Qt Standard Dialogs</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | [ <a href="motif-walkthrough-2.html">Previous: Preparing to Migrate the User Interface</a> ]
|
---|
37 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
38 | [ <a href="motif-walkthrough-4.html">Next: Using Custom QDialogs</a> ]
|
---|
39 | <p> We start by using two of the <a href="dialogs.html">Qt Standard
|
---|
40 | Dialogs</a>: <a href="qfiledialog.html">QFileDialog</a> and <a href="qmessagebox.html">QMessageBox</a>. Both of these classes
|
---|
41 | provide useful static convenience functions.
|
---|
42 | <p> <center><table cellpadding="4" cellspacing="2" border="0">
|
---|
43 | <tr bgcolor="#f0f0f0"> <td valign="top">QFileDialog::getOpenFileName() <td valign="top">replacement for the <em>Open</em> dialog
|
---|
44 | <tr bgcolor="#d0d0d0"> <td valign="top">QFileDialog::getSaveFileName() <td valign="top">replacement for the <em>Save As</em> dialog
|
---|
45 | <tr bgcolor="#f0f0f0"> <td valign="top">QMessageBox::information() <td valign="top">replacement for <em>Page Delete</em> dialog
|
---|
46 | <tr bgcolor="#d0d0d0"> <td valign="top">QMessageBox::warning() <td valign="top">replacement for <em>IO Error</em> dialog.
|
---|
47 | </table></center>
|
---|
48 | <p> Each of these functions takes a <em>QWidget *parent</em> argument. If we
|
---|
49 | pass zero as the <em>parent</em> argument, then we will have dialogs that
|
---|
50 | are centered on the screen, instead of being centered over our main
|
---|
51 | window. We can have <a href="qmotifwidget.html">QMotifWidget</a> create our <tt>XmMainWindow</tt>, and we
|
---|
52 | can then use this class as the parent for both <a href="motif-extension.html#Motif">Motif</a> dialogs and Qt
|
---|
53 | dialogs.
|
---|
54 | <p> We need to include the appropriate headers for QMotifWidget and
|
---|
55 | <a href="qfiledialog.html">QFileDialog</a> in <tt>todo.cpp</tt>.
|
---|
56 | <p>
|
---|
57 |
|
---|
58 | <pre></pre>
|
---|
59 | <p> Next, we make a few modifications to how the application is
|
---|
60 | 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.
|
---|
61 | We also let <a href="qapplication.html">QApplication</a> open the connection to the X server. Next,
|
---|
62 | 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>()
|
---|
63 | function to access the Motif widget. The shell widget is created
|
---|
64 | automatically by QMotifWidget. We use <tt>XtParent()</tt> to access it.
|
---|
65 | The top-level window is now a QMotifWidget, which means we can use it
|
---|
66 | as the parent for the Qt Standard Dialogs.
|
---|
67 | <p> <pre></pre>
|
---|
68 | <p> <h2> Replacing the <em>Open</em> and <em>Save As</em> Dialogs
|
---|
69 | </h2>
|
---|
70 | <a name="1"></a><p> First, we completely remove all use of the existing Motif file
|
---|
71 | 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
|
---|
72 | remove the <tt>PresentFDialog()</tt> callback function. None of this code
|
---|
73 | is needed to use <a href="qfiledialog.html">QFileDialog</a>.
|
---|
74 | <p> After removing the <tt>PresentFDialog()</tt> callback function, we need to
|
---|
75 | make <em>Open</em> and <em>Save As</em> popup-menu callbacks call the <tt>Open()</tt>
|
---|
76 | and <tt>Save()</tt> functions.
|
---|
77 | <p> First we must change the declaration of these two functions.
|
---|
78 | <p>
|
---|
79 |
|
---|
80 | <p> <pre></pre>
|
---|
81 | <p> We also change the arguments to the callbacks. We pass the top-level
|
---|
82 | <a href="qmotifwidget.html">QMotifWidget</a> as the <tt>client_data</tt> to these functions, since we will
|
---|
83 | be using it as the parent for the QFileDialog.
|
---|
84 | <p> <pre></pre>
|
---|
85 | <p> <pre>
|
---|
86 | ...
|
---|
87 | </pre>
|
---|
88 |
|
---|
89 | <p> <pre></pre>
|
---|
90 | <p> Next, we modify the <tt>Save()</tt> function to use
|
---|
91 | <a href="qfiledialog.html#getSaveFileName">QFileDialog::getSaveFileName</a>().
|
---|
92 | <p> <pre></pre>
|
---|
93 | <p> ... and the <tt>Open()</tt> function to use <a href="qfiledialog.html#getOpenFileName">QFileDialog::getOpenFileName</a>().
|
---|
94 | <p> <pre></pre>
|
---|
95 | <p> After we build the project, the application runs and operates as
|
---|
96 | expected. The difference is that the <em>Open</em> and <em>Save As</em> dialogs
|
---|
97 | now use <a href="qfiledialog.html">QFileDialog</a>.
|
---|
98 | <p> <h2> Replacing the <em>Page Delete</em> and <em>IO Error</em> Dialogs
|
---|
99 | </h2>
|
---|
100 | <a name="2"></a><p> The <em>Page Delete</em> dialog is created and used in <tt>actions.c</tt>. We
|
---|
101 | need to migrate this file to C++. We rename it to <tt>actions.cpp</tt>,
|
---|
102 | modify the project file and regenerate the <tt>Makefile</tt>.
|
---|
103 | <p> The changes required to make <tt>actions.cpp</tt> compile are minimal. We
|
---|
104 | need to wrap more C header files and global variables in an <tt>extern "C"</tt> block.
|
---|
105 | <p>
|
---|
106 |
|
---|
107 | <p> <pre></pre>
|
---|
108 | <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
|
---|
109 | the correct symbols for these functions.
|
---|
110 | <p> <pre></pre>
|
---|
111 | <p> We need to fix a single invalid pointer cast.
|
---|
112 | <p> <pre></pre>
|
---|
113 | <p> And we need to change the variable named <em>new</em> to <em>newstr</em> in the <tt>Trim()</tt> function.
|
---|
114 | <p> We can now change the <tt>DeletePage()</tt> function to use
|
---|
115 | <a href="qmessagebox.html#information">QMessageBox::information</a>().
|
---|
116 | <p> First, we need to make sure we include the proper header for
|
---|
117 | <a href="qmessagebox.html">QMessageBox</a>.
|
---|
118 | <p>
|
---|
119 |
|
---|
120 | <pre></pre>
|
---|
121 | <p> The code for <tt>DeletePage()</tt> looks like this:
|
---|
122 | <p> <pre></pre>
|
---|
123 | <p> At this point in the code, the page should be deleted. The code to do
|
---|
124 | 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
|
---|
125 | completely.
|
---|
126 | <p> Next, we change <tt>todo.cpp</tt> to pass the top-level <a href="qmotifwidget.html">QMotifWidget</a> as the
|
---|
127 | <tt>client_data</tt> tot he <tt>DeletePage()</tt> function.
|
---|
128 | <p>
|
---|
129 |
|
---|
130 | <p> <pre></pre>
|
---|
131 | <p> The <em>IO Error</em> dialog is created and used in <tt>io.c</tt>. We need to
|
---|
132 | migrate this file to C++. We rename it to <tt>io.cpp</tt>, modify the
|
---|
133 | project file and regenerate the <tt>Makefile</tt>.
|
---|
134 | <p> The changes required to make <tt>io.cpp</tt> compile are minimal. We need
|
---|
135 | to wrap more C header files and global variables in an <tt>extern "C"</tt>
|
---|
136 | block.
|
---|
137 | <p>
|
---|
138 |
|
---|
139 | <p> <pre></pre>
|
---|
140 | <p> We need to forward declare the <tt>ReadDB()</tt> and <tt>SaveDB()</tt> functions
|
---|
141 | so that the compiler generates the correct symbols for these
|
---|
142 | functions.
|
---|
143 | <p> <pre></pre>
|
---|
144 | <p> The <tt>ParseNewLines()</tt> function needs to be converted to proper C++.
|
---|
145 | <p> <pre></pre>
|
---|
146 | <p> The <tt>PrintWithNewLines()</tt> function also needs to be converted to proper
|
---|
147 | C++.
|
---|
148 | <p> <pre></pre>
|
---|
149 | <p> We can now change the <tt>ReadDB()</tt> and <tt>SaveDB()</tt> functions to use
|
---|
150 | <a href="qmessagebox.html#warning">QMessageBox::warning</a>().
|
---|
151 | <p> First, we need to make sure we include the proper header for <a href="qmessagebox.html">QMessageBox</a>.
|
---|
152 | <p>
|
---|
153 |
|
---|
154 | <pre></pre>
|
---|
155 | <p> The code for <tt>ReadDB()</tt> looks like this:
|
---|
156 | <p> <pre></pre><pre>
|
---|
157 | ...
|
---|
158 | </pre>
|
---|
159 |
|
---|
160 | <p> The code for <tt>SaveDB()</tt> looks like this:
|
---|
161 | <p> <pre></pre><pre>
|
---|
162 | ...
|
---|
163 | </pre>
|
---|
164 |
|
---|
165 | <p> After we build the project, the application runs and operates as
|
---|
166 | expected. The difference is that the <em>Page Delete</em> and <em>IO Error</em> dialogs now use QMessageBox.
|
---|
167 | <p> [ <a href="motif-walkthrough-2.html">Previous: Preparing to Migrate the User Interface</a> ]
|
---|
168 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
169 | [ <a href="motif-walkthrough-4.html">Next: Using Custom QDialogs</a> ]
|
---|
170 | <p>
|
---|
171 | <!-- eof -->
|
---|
172 | <p><address><hr><div align=center>
|
---|
173 | <table width=100% cellspacing=0 border=0><tr>
|
---|
174 | <td>Copyright © 2007
|
---|
175 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
176 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
177 | </table></div></address></body>
|
---|
178 | </html>
|
---|