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:776 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>Using Qt Main Window Classes</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 Main Window Classes</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | [ <a href="motif-walkthrough-5.html">Previous: Using Existing Dialogs with QMotifDialog</a> ]
|
---|
37 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
38 | [ <a href="motif-walkthrough-7.html">Next: Refactoring Existing Code</a> ]
|
---|
39 | <p> After we have replaced all the dialogs, we are ready to begin replacing
|
---|
40 | the <em>Main Window</em>. <a href="motif-walkthrough.html#4">As mentioned
|
---|
41 | above</a>, we will replace the existing <tt>XmMainWindow</tt> and
|
---|
42 | popup-menu heirarchy with <a href="application.html">Qt Main Window
|
---|
43 | Classes</a>.
|
---|
44 | <p> We will use <a href="designer-manual.html">Qt Designer</a> to design
|
---|
45 | our new main window.
|
---|
46 | <p> <h2> Implementing the <em>Main Window</em>
|
---|
47 | </h2>
|
---|
48 | <a name="1"></a><p> The description for the <em>Main Window</em> is saved as <tt>mainwindow.ui</tt>.
|
---|
49 | We add this file to the project file and regenerate the <tt>Makefile</tt>.
|
---|
50 | The <em>uic</em> utility generates the code for our <em>Main Window</em>, which
|
---|
51 | is then compiled and linked into our application.
|
---|
52 | <p> <em>Qt Designer</em> also created the <tt>mainwindow.ui.h</tt> file. We need to
|
---|
53 | add the implementation for our <em>Main Window</em> to this skeleton
|
---|
54 | implementation.
|
---|
55 | <p> We begin by adding the necessary includes for <a href="qapplication.html">QApplication</a>
|
---|
56 | and <a href="qmotifwidget.html">QMotifWidget</a>.
|
---|
57 | <p>
|
---|
58 |
|
---|
59 | <p> <pre></pre>
|
---|
60 | <p> We need includes for the <a href="motif-extension.html#Motif">Motif</a> callback structs and the <tt>XmdPrint</tt>
|
---|
61 | widget.
|
---|
62 | <p> <pre></pre><pre></pre>
|
---|
63 | <p> We are now ready to add implementations for the slots in our <em>Main Window</em>. We have one slot per menu item. Each slot will call the
|
---|
64 | existing callback functions found in <tt>todo.cpp</tt> and <tt>actions.cpp</tt>.
|
---|
65 | <p> <center><table cellpadding="4" cellspacing="2" border="0">
|
---|
66 | <tr bgcolor="#a2c511"> <th valign="top" colspan="3" rowspan="1"> File menu
|
---|
67 | <tr bgcolor="#f0f0f0"> <td valign="top">New <td valign="top"><tt>MainWindow::fileNew()</tt> <td valign="top">calls the <tt>New()</tt> callback
|
---|
68 | <tr bgcolor="#d0d0d0"> <td valign="top">Open <td valign="top"><tt>MainWindow::fileOpen()</tt> <td valign="top">calls the <tt>Open()</tt> callback
|
---|
69 | <tr bgcolor="#f0f0f0"> <td valign="top">Save <td valign="top"><tt>MainWindow::fileSave()</tt> <td valign="top">calls the <tt>SaveIt()</tt> callback
|
---|
70 | <tr bgcolor="#d0d0d0"> <td valign="top">Save As <td valign="top"><tt>MainWindow::fileSaveAs()</tt> <td valign="top">calls the <tt>Save()</tt> callback
|
---|
71 | <tr bgcolor="#f0f0f0"> <td valign="top">Print <td valign="top"><tt>MainWindow::filePrint()</tt> <td valign="top">calls the <tt>ShowPrintDialog()</tt> callback
|
---|
72 | <tr bgcolor="#d0d0d0"> <td valign="top">Exit <td valign="top"><tt>MainWindow::fileExit()</tt> <td valign="top">calls <a href="qapplication.html#quit">QApplication::quit</a>()
|
---|
73 | <tr bgcolor="#a2c511"> <th valign="top" colspan="3" rowspan="1"> Selected menu
|
---|
74 | <tr bgcolor="#f0f0f0"> <td valign="top">Properties <td valign="top"><tt>MainWindow::selProperties()</tt> <td valign="top">calls the <tt>EditPage()</tt> callback
|
---|
75 | <tr bgcolor="#d0d0d0"> <td valign="top">New <td valign="top"><tt>MainWindow::selNewPage()</tt> <td valign="top">calls the <tt>NewPage()</tt> callback
|
---|
76 | <tr bgcolor="#f0f0f0"> <td valign="top">Delete to Trash <td valign="top"><tt>MainWindow::selDeletePage()</tt> <td valign="top">calls the <tt>DeletePage()</tt> callback
|
---|
77 | </table></center>
|
---|
78 | <p> We need to add forward declarations for these callbacks before we can
|
---|
79 | use them.
|
---|
80 | <p> <pre></pre>
|
---|
81 | <p> Each of the existing callback functions takes three arguments. We pass
|
---|
82 | <em>NULL</em> to all of the arguments in this example (with a few exceptions,
|
---|
83 | see below). The existing code does not rely on any of the arguments.
|
---|
84 | Each slot implementation is a single line calling the related callback
|
---|
85 | function. The code is not very interesting and would just take up
|
---|
86 | space, so we've omitted it.
|
---|
87 | <p> There are four exceptions to the above. The <tt>Open()</tt>, <tt>Save()</tt>, <tt>EditPage()</tt> and <tt>DeletePage()</tt> callbacks accept a pointer to the
|
---|
88 | toplevel <a href="qwidget.html">QWidget</a> as argument 2 (the <em>client_data</em> argument). For
|
---|
89 | these four functions, we pass <em>this</em> as the second argument, which is
|
---|
90 | a toplevel <tt>MainWindow</tt> derived from <a href="qmainwindow.html">QMainWindow</a>.
|
---|
91 | <p> <h2> Replacing the <em>Main Window</em>
|
---|
92 | </h2>
|
---|
93 | <a name="2"></a><p> The next step is to use the new <em>Main Window</em> in our application.
|
---|
94 | The changes needed in <tt>todo.cpp</tt> are large due to the large amount of
|
---|
95 | code being removed.
|
---|
96 | <p> First, we add the include for our new <em>Main Window</em>.
|
---|
97 | <p>
|
---|
98 |
|
---|
99 | <p> <pre></pre>
|
---|
100 | <p> We can cleanup the Motif includes, since many of them are no longer
|
---|
101 | needed.
|
---|
102 | <p> <pre></pre><pre></pre><pre></pre>
|
---|
103 | <p> The <tt>QuitAppl()</tt> and <tt>manageCB()</tt> callbacks are not needed any more,
|
---|
104 | so we remove them. We do not need the global <tt>shell</tt> variable
|
---|
105 | either. We remove it and all references to it in the <tt>New()</tt>, <tt>Save()</tt> and <tt>Open()</tt> callbacks.
|
---|
106 | <p> In <tt>main()</tt>, we make the large changes. First, we use our new <tt>MainWindow</tt> instead of <a href="qmotifwidget.html">QMotifWidget</a> with <tt>XmMainWindow</tt>.
|
---|
107 | <p>
|
---|
108 |
|
---|
109 | <p> <pre></pre>
|
---|
110 | <p> We will now use QMotifWidget to create the <tt>XmNotebook</tt> widget.
|
---|
111 | <p> <pre></pre>
|
---|
112 | <p> We remove all of the code used to create the Motif menus. The
|
---|
113 | remaining code in <tt>main()</tt> is self-explanatory.
|
---|
114 | <p> <pre></pre>
|
---|
115 | <p> Our application is now using <a href="qmainwindow.html">QMainWindow</a> instead of <tt>XmMainWindow</tt>.
|
---|
116 | After we build the project, the application runs and operates as
|
---|
117 | expected.
|
---|
118 | <p> [ <a href="motif-walkthrough-5.html">Previous: Using Existing Dialogs with QMotifDialog</a> ]
|
---|
119 | [ <a href="motif-walkthrough.html">Home</a> ]
|
---|
120 | [ <a href="motif-walkthrough-7.html">Next: Refactoring Existing Code</a> ]
|
---|
121 | <p>
|
---|
122 | <!-- eof -->
|
---|
123 | <p><address><hr><div align=center>
|
---|
124 | <table width=100% cellspacing=0 border=0><tr>
|
---|
125 | <td>Copyright © 2007
|
---|
126 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
127 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
128 | </table></div></address></body>
|
---|
129 | </html>
|
---|