📄 designer-manual-8.html
字号:
<h4><a name="3-1"></a>Creating Makefiles without qmake</h4><!-- index Makefiles --><p>The <tt>qmake</tt> tool provided with Qt can create Makefiles appropriate to your platform based on<!-- index .pro --> <tt>.pro</tt> project files. This section describes the dependencies involved in building a Qt application and gives a couple of simple example Makefiles. This section assumes that you have a good understanding of Makefiles.</p><!-- index Macros!Q_OBJECT --><!-- index Q_OBJECT --><p><em>Qt Designer</em> produces<!-- index .ui --> <tt>.ui</tt> files which are used to generate<!-- index .h --> <tt>.h</tt> and<!-- index .cpp --> <tt>.cpp</tt> files for the compiler to compile. The<!-- index .ui --> <tt>.ui</tt> files are processed by <tt>uic</tt>. Classes which inherit from <b>QObject</b>, e.g. those which use slots and signals, require an additional<!-- index .cpp --> <tt>.cpp</tt> file to be generated. These files are generated by the <tt>moc</tt> and are named '<em>moc_</em>file.cpp' where the original<!-- index .cpp --> <tt>.cpp</tt> file is called 'file.cpp'. If your<!-- index .cpp --> <tt>.cpp</tt> file contains the <tt>Q_OBJECT</tt> macro an additional file 'file.moc' should be generated which must be <tt>#include</tt>d in the<!-- index .cpp --> <tt>.cpp</tt>, normally at the end. This requires an extra dependency being created.</p><p>Processing<!-- index .ui --> <tt>.ui</tt> files with <tt>uic</tt> is done <em>twice</em>:</p><pre>uic myform.ui -o myform.huic myform.ui -i myform.h -o myform.cpp</pre><p>The first execution creates the header file, the second creates the<!-- index .cpp --> <tt>.cpp</tt> file. If you wish to subclass a form you can use <tt>uic</tt> to generate subclass skeletons:</p><pre>uic formbase.ui -o formbase.huic formbase.ui -i formbase.h -o formbase.cppuic -subdecl Form formbase.h formbase.ui -o form.huic -subimpl Form form.h formbase.ui -o form.cpp</pre><p>First we generate the header and implementation file for our base class. Then we generate the header and implementation skeletons for our subclass. Note that the use of <tt>uic</tt> to generate skeletons is not something that would be done in a Makefile, we mention it here because it can be useful for command line users. Note also that the command line for <tt>-subdecl</tt> and for <tt>subimpl</tt> are subtly different.</p><p>For implementation files that contain classes which inherit from <b>QObject</b> we must create moc files:</p><pre>moc myform.h -o moc_myform.cpp</pre><p>We'll look at a simple Makefile to see the dependencies in practice.</p><pre>myapp: moc_myform.o myform.o main.o g++ -lqt -o myapp moc_myform.o myform.o main.omain.o: main.cpp g++ -o main.o main.cppmoc_myform.o: moc_myform.cpp g++ -o moc_myform.o moc_myform.cppmoc_myform.cpp: myform.h moc myform.h -o moc_myform.cppmyform.o: myform.cpp g++ -o myform.o myform.cppmyform.cpp: myform.h myform.ui uic myform.ui -i myform.h -o myform.cppmyform.h: myform.ui uic myform.ui -o myform.h</pre><p>Note that you may need to include the full path to the commands in your Makefile, and under Windows the filenames are<!-- index moc.exe --> <tt>moc.exe</tt> and<!-- index uic.exe --> <tt>uic.exe</tt>.</p><p>In Unix/Linux environments the <tt>make</tt> command may be able to do more for us, so we should be able to use a simpler Makefile like this:</p><pre>myapp: moc_myform.o myform.o main.o g++ -lq -o $@ $^%.o: %.cpp g++ -o $^ $@moc_%.cpp: %.h moc $^ -o $@myform.cpp: myform.h myform.ui uic myform.ui -i myform.h -o myform.cppmyform.h: myform.ui uic myform.ui -o myform.h</pre><p>To see more sophisticated Makefiles simply generate them using <tt>qmake</tt> on any of your Qt projects or any of the examples supplied with Qt.</p><h3><a name="4"></a>Importing Foreign File Formats</h3><!-- index Foreign File Formats --><p>To import a file in a supported foreign file format click <b>File|Open</b>, then click the File Type combobox to choose the file type you wish to load. Click the required file and <em>Qt Designer</em> will convert and load the file.</p><p>The filters that <em>Qt Designer</em> uses to read foreign file formats are 'works in progress'. You may have different filters available in your version of <em>Qt Designer</em> than those described here. The easiest way to see which filters are available is to invoke the file open dialog; all your filters are listed in the File Type combobox.</p><h4><a name="4-1"></a>Importing Qt Architect Files</h4><!-- index Foreign File Formats!Qt Architect --><!-- index Qt Architect --><p><a href="http://qtarch.sourceforge.net/">Qt Architect</a> is a free GUI builder for Qt written by Jeff Harris and Klaus Ebner. The<!-- index .dlg --> <tt>.dlg</tt> extension is associated with Qt Architect dialog files.</p><p><em>Qt Designer</em> can read files generated by Qt Architect version 2.1 and above. When given a<!-- index .dlg --> <tt>.dlg</tt> file from a previous version of Qt Architect, <em>Qt Designer</em> tells you how to convert it to the file format of version 2.1. (The conversion procedure varies depending on the version of the<!-- index .dlg --> <tt>.dlg</tt> file.)</p><p>The import filter does a good job of importing<!-- index .dlg --> <tt>.dlg</tt> files; the result is almost identical to what you get in Qt Architect. However, the C++ code that uses the dialogs will probably need some adaptation.</p><p>There are a few drawbacks to converting Qt Architect files to <em>Qt Designer</em>'s format due to differences between the two tools; these are listed below:</p><ul><li><p>Layout spacing and margins</p><p>If the<!-- index .dlg --> <tt>.dlg</tt> file layouts use the Qt Architect defaults for layout spacing and margins, <em>Qt Designer</em> will override these with its standard defaults. You can change the "layoutSpacing" and "layoutMargin" properties manually afterwards if necessary.</p><li><p>Layout stretches and spacings</p><p>Qt Architect gives access to more features of Qt's layout system than <em>Qt Designer</em>, namely stretches and spacings. Qt Designer will attempt to cope with<!-- index .dlg --> <tt>.dlg</tt> files that use these features, but sometimes the resizing will not be what you want. The solution typically involves setting the "sizePolicy" properties of some widgets and inserting or deleting spacers.</p><li><p>Mixing managed and unmanaged widgets</p><p>Qt Architect allows a widget to have some child widgets managed by a layout and other child widgets with fixed positions. When presented with a<!-- index .dlg --> <tt>.dlg</tt> file that uses this facility, <em>Qt Designer</em> will silently put the fixed position widgets into the layout.</p><li><p>Pixmaps</p><p><em>Qt Designer</em> ignores pixmaps specified in<!-- index .dlg --> <tt>.dlg</tt> files. These have to be restored manually in <em>Qt Designer</em>.</p></ul><h4><a name="4-2"></a>Importing Glade Files</h4><!-- index Foreign File Formats!Glade --><!-- index Glade --><p><a href="http://glade.pn.org/">Glade</a> is a free GUI builder for GTK+ and GNOME written by Damon Chaplin. The<!-- index .glade --> <tt>.glade</tt> extension is associated with Glade files.</p><p><em>Qt Designer</em> has been tested with Glade files up to version 0.6.0 and might work with later versions as well.</p><p>Although Glade does not target Qt, the layout system and the widget set of GTK+ are similar to those of Qt, so the filter will retain most of the information in the<!-- index .glade --> <tt>.glade</tt> file.</p><p>There are some considerations regarding the conversion of Glade files, as listed below:</p><ul><li><p>Ampersands (&) in labels</p><p>Qt displays an ampersand when a <b>QLabel</b> has no buddy. (A buddy is a widget that accepts focus on behalf of a <b>QLabel</b>.) Glade allows GtkLabel widgets with an (underlined) accelerator key but with no buddy. This is an error since users expect underlined characters to be accelerators. In this situation, Qt displays the ampersand itself instead of underlining the accelerator key. You should go over these <b>QLabel</b> widgets and set their "<em>buddy</em>" property.</p><li><p>Layout placeholders</p><p>GTK allows a layout position to be occupied by a placeholder. <em>Qt Designer</em> converts those placeholders into <b>QLabel</b>s whose text is "?" in red, so that you can find them and fix them manually.</p><li><p>GTK+ or GNOME widget with no Qt equivalent</p><p>Qt has equivalents for most GTK+ widgets, but Glade also supports GNOME, whose goal is to provide a complete desktop environment. Because Qt's scope is narrower, when <em>Qt Designer</em> encounters a widget it cannot convert, it replaces it with a label that indicates the problem. For example, a GnomePaperSelector will be replaced by a <b>QLabel</b> whose text is "GnomePaperSelector?" in red. If you are porting to KDE, you might want to use the corresponding KDE widget.</p><p>Other GTK+/GNOME widgets are only supported in certain contexts. For example, the GnomeDruid can be embedded in another widget, whereas the corresponding <b>QWizard</b> class cannot.</p><li><p>Message boxes and other high-level dialogs</p><p>Glade supports editing of GnomeMessageBox, GtkFileSelection, GtkFontSelectionDialog and others. This is trivially achieved in Qt by means of a <b>QMessageBox</b> dialog, a <b>QFileDialog</b>, a <b>QFontDialog</b>, etc., in C++ code.</p><li><p>Stand-alone popup menus</p><p><em>Qt Designer</em> only supports popup menus inside a <b>QMainWindow</b>. If you need a stand-alone popup menu (presumably a context menu), you can easily write code that does this using <b>QPopupMenu</b>.</p><li><p>Size policy parameters</p><p>Glade provides size policies in the "Place" tab of the property editor. <em>Qt Designer</em> does not attempt to make use of the padding, expand, shrink and fill information, as the Qt defaults are usually good enough. In a few cases, you might have to set the "<em>sizePolicy</em>" property manually to obtain the effect you want.</p><li><p>GNOME standard icons</p><p>GNOME provides a large set of standard icons. <em>Qt Designer</em> will ignore references to these. If you are porting to KDE, you might want to manually set the standard KDE icons.</p><li><p>Packer layout</p><p>GTK+ provides a class called GtkPacker that provides for exotic layouts; Qt provides no <b>QPackerLayout</b> and never will. <em>Qt Designer</em> will treat packer layouts as if they were vertical layouts and you will probably have to change them to whatever combination of layouts that produces the right effect.</p><li><p>Incorrectly-justified text after conversion</p><p>The "<em>hAlign</em>" property is sometimes set wrongly, in which case you have to change it manually. It is caused by a quirk in Glade.</p></ul><!-- eof --><p align="right">[<a href="designer-manual-7.html">Prev: Creating Database Applications</a>] [<a href="designer-manual.html">Home</a>] [<a href="designer-manual-9.html">Next: Reference: Key Bindings</a>]</p><p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -