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/qmake/book/qmake-quick.leaf:3 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>The 10 minute guide to using qmake</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><p align="right">[<a href="qmake-manual-2.html">Prev: Installing qmake</a>] [<a href="qmake-manual.html">Home</a>] [<a href="qmake-manual-4.html">Next: qmake Tutorial</a>]</p>
|
---|
33 | <h2 align="center">The 10 minute guide to using qmake</h2>
|
---|
34 | <h3><a name="1"></a>Creating a project file</h3>
|
---|
35 | <p><em>qmake</em> uses information stored in project (.pro) files to determine what should go in the makefiles it generates.</p>
|
---|
36 | <p>A basic project file contains information about the application, for example, which files are needed to compile the application, and which configuration settings to use.</p>
|
---|
37 | <p>Here's a simple example project file:</p>
|
---|
38 | <pre>
|
---|
39 | SOURCES = hello.cpp
|
---|
40 | HEADERS = hello.h
|
---|
41 | CONFIG += qt warn_on release
|
---|
42 | </pre>
|
---|
43 | <p>We'll provide a brief line-by-line explanation, deferring the detail until later on in the manual.</p>
|
---|
44 | <pre>
|
---|
45 | SOURCES = hello.cpp
|
---|
46 | </pre>
|
---|
47 | <p>This line specifies the source files that implement the application. In this case there is just one file, <em>hello.cpp</em>. Most applications require multiple files; this situation is dealt with by listing all the files on the same line space separated, like this:</p>
|
---|
48 | <pre>
|
---|
49 | SOURCES = hello.cpp main.cpp
|
---|
50 | </pre>
|
---|
51 | <p>Alternatively, each file can be listed on a separate line, by escaping the newlines, like this:</p>
|
---|
52 | <pre>
|
---|
53 | SOURCES = hello.cpp \
|
---|
54 | main.cpp
|
---|
55 | </pre>
|
---|
56 | <p>A more verbose approach is to list each file separately, like this:</p>
|
---|
57 | <pre>
|
---|
58 | SOURCES += hello.cpp
|
---|
59 | SOURCES += main.cpp
|
---|
60 | </pre>
|
---|
61 | <p>This approach uses "+=" rather than "=" which is safer, because it always adds a new file to the existing list rather than replacing the list.</p>
|
---|
62 | <p>The HEADERS line is used to specify the header files created for use by the application, e.g.</p>
|
---|
63 | <pre>
|
---|
64 | HEADERS += hello.h
|
---|
65 | </pre>
|
---|
66 | <p>Any of the approaches used to list source files may be used for header files.</p>
|
---|
67 | <p>The CONFIG line is used to give <em>qmake</em> information about the application's configuration.</p>
|
---|
68 | <pre>
|
---|
69 | CONFIG += qt warn_on release
|
---|
70 | </pre>
|
---|
71 | <p>The "+=" is used here, because we add our configuration options to any that are already present. This is safer than using "=" which replaces all options with just those specified.</p>
|
---|
72 | <p>The <em>qt</em> part of the CONFIG line tells <em>qmake</em> that the application is built using Qt. This means that <em>qmake</em> will link against the Qt libraries when linking and add in the neccesary include paths for compiling.</p>
|
---|
73 | <p>The <em>warn_on</em> part of the CONFIG line tells <em>qmake</em> that it should set the compiler flags so that warnings are output.</p>
|
---|
74 | <p>The <em>release</em> part of the CONFIG line tells <em>qmake</em> that the application must be built as a release application. During development, programmers may prefer to replace <em>release</em> with <em>debug</em>, which is discussed later.</p>
|
---|
75 | <p>Project files are plain text (i.e. use an editor like notepad, vim or xemacs) and must be saved with a '.pro' extension. The name of the application's executable will be the same as the project file's name, but with an extension appropriate to the platform. For example, a project file called 'hello.pro' will produce 'hello.exe' on Windows and 'hello' on Unix.</p>
|
---|
76 | <h3><a name="2"></a>Generating a makefile</h3>
|
---|
77 | <p>When you have created your project file it is very easy to generate a makefile, all you need to do is go to where you have created your project file and type:</p>
|
---|
78 | <p>Makefiles are generated from the '.pro' files like this:</p>
|
---|
79 | <pre>
|
---|
80 | qmake -o Makefile hello.pro
|
---|
81 | </pre>
|
---|
82 | <p>For Visual Studio users, <em>qmake</em> can also generate '.dsp' files, for example:</p>
|
---|
83 | <pre>
|
---|
84 | qmake -t vcapp -o hello.dsp hello.pro
|
---|
85 | </pre>
|
---|
86 | <!-- eof -->
|
---|
87 | <p align="right">[<a href="qmake-manual-2.html">Prev: Installing qmake</a>] [<a href="qmake-manual.html">Home</a>] [<a href="qmake-manual-4.html">Next: qmake Tutorial</a>]</p>
|
---|
88 | <p><address><hr><div align=center>
|
---|
89 | <table width=100% cellspacing=0 border=0><tr>
|
---|
90 | <td>Copyright © 2007
|
---|
91 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
92 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
93 | </table></div></address></body>
|
---|
94 | </html>
|
---|