source: trunk/doc/src/files-and-resources/resources.qdoc@ 788

Last change on this file since 788 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

  • Property svn:eol-style set to native
File size: 8.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*!
43 \group io
44 \title Input/Output and Networking
45 \ingroup groups
46
47 \brief Classes providing file input and output along with directory and
48 network handling.
49
50 These classes are used to handle input and output to and from external
51 devices, processes, files etc. as well as manipulating files and directories.
52*/
53
54/*!
55 \page resources.html
56 \title The Qt Resource System
57
58 \keyword resource system
59
60 The Qt resource system is a platform-independent mechanism for
61 storing binary files in the application's executable. This is
62 useful if your application always needs a certain set of files
63 (icons, translation files, etc.) and you don't want to run the
64 risk of losing the files.
65
66 The resource system is based on tight cooperation between \l qmake,
67 \l rcc (Qt's resource compiler), and QFile. It obsoletes Qt 3's
68 \c qembed tool and the
69 \l{http://qt.nokia.com/doc/qq/qq05-iconography.html#imagestorage}{image
70 collection} mechanism.
71
72 \section1 Resource Collection Files (\c{.qrc})
73
74 The resources associated with an application are specified in a
75 \c .qrc file, an XML-based file format that lists files on the
76 disk and optionally assigns them a resource name that the
77 application must use to access the resource.
78
79 Here's an example \c .qrc file:
80
81 \quotefile mainwindows/application/application.qrc
82
83 The resource files listed in the \c .qrc file are files that are
84 part of the application's source tree. The specified paths are
85 relative to the directory containing the \c .qrc file. Note that
86 the listed resource files must be located in the same directory as
87 the \c .qrc file, or one of its subdirectories.
88
89 Resource data can either be compiled into the binary and thus accessed
90 immediately in application code, or a binary resource can be created
91 and at a later point in application code registered with the resource
92 system.
93
94 By default, resources are accessible in the application under the
95 same name as they have in the source tree, with a \c :/ prefix.
96 For example, the path \c :/images/cut.png would give access to the
97 \c cut.png file, whose location in the application's source tree
98 is \c images/cut.png. This can be changed using the \c file tag's
99 \c alias attribute:
100
101 \snippet doc/src/snippets/code/doc_src_resources.qdoc 0
102
103 The file is then accessible as \c :/cut-img.png from the
104 application. It is also possible to specify a path prefix for all
105 files in the \c .qrc file using the \c qresource tag's \c prefix
106 attribute:
107
108 \snippet doc/src/snippets/code/doc_src_resources.qdoc 1
109
110 In this case, the file is accessible as \c
111 :/myresources/cut-img.png.
112
113 Some resources, such as translation files and icons, many need to
114 change based on the user's locale. This is done by adding a \c lang
115 attribute to the \c qresource tag, specifying a suitable locale
116 string. For example:
117
118 \snippet doc/src/snippets/code/doc_src_resources.qdoc 2
119
120 If the user's locale is French (i.e., QLocale::system().name() returns
121 "fr_FR"), \c :/cut.jpg becomes a reference to the \c cut_fr.jpg
122 image. For other locales, \c cut.jpg is used.
123
124 See the QLocale documentation for a description of the format to use
125 for locale strings.
126
127
128 \section2 External Binary Resources
129