1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
\chapter The 10 minute guide to using qmake
\section1 Creating a project file
\e qmake uses information stored in project (.pro) files to determine
what should go in the makefiles it generates.
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.
Here's a simple example project file:
\code
SOURCES = hello.cpp
HEADERS = hello.h
CONFIG += qt warn_on release
\endcode
We'll provide a brief line-by-line explanation, deferring the detail
until later on in the manual.
\code
SOURCES = hello.cpp
\endcode
This line specifies the source files that implement the application. In this
case there is just one file, \e hello.cpp. Most applications require
multiple files; this situation is dealt with by listing all the files
on the same line space separated, like this:
\code
SOURCES = hello.cpp main.cpp
\endcode
Alternatively, each file can be listed on a separate line, by escaping
the newlines, like this:
\code
SOURCES = hello.cpp \
main.cpp
\endcode
A more verbose approach is to list each file separately, like this:
\code
SOURCES += hello.cpp
SOURCES += main.cpp
\endcode
This approach uses "+=" rather than "=" which is safer, because it
always adds a new file to the existing list rather than replacing the
list.
The HEADERS line is used to specify the header files created for use
by the application, e.g.
\code
HEADERS += hello.h
\endcode
Any of the approaches used to list source files may be used for header
files.
The CONFIG line is used to give \e qmake information about the
application's configuration.
\code
CONFIG += qt warn_on release
\endcode
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.
The \e qt part of the CONFIG line tells \e qmake that the application
is built using Qt. This means that \e qmake will link against the Qt
libraries when linking and add in the neccesary include paths for
compiling.
The \e warn_on part of the CONFIG line tells \e qmake that it should
set the compiler flags so that warnings are output.
The \e release part of the CONFIG line tells \e qmake that the
application must be built as a release application. During
development, programmers may prefer to replace \e release with \e
debug, which is discussed later.
\omit
The last line in the project file is the TARGET line:
\code
TARGET = hello
\endcode
The target line simply specifies what the name of the target should be
for the application. You shouldn't put an extension here because \e
qmake will do this for you.
\endomit
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.
\section1 Generating a makefile
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:
Makefiles are generated from the '.pro' files like this:
\code
qmake -o Makefile hello.pro
\endcode
For Visual Studio users, \e qmake can also generate '.dsp' files, for
example:
\code
qmake -t vcapp -o hello.dsp hello.pro
\endcode
|