bcee8564c0f4de51645f26311242e00b4f0e9d1a
[profile/ivi/qtdeclarative.git] / doc / src / qtquick1 / network.qdoc
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the documentation of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:FDL$
10 ** GNU Free Documentation License
11 ** Alternatively, this file may be used under the terms of the GNU Free
12 ** Documentation License version 1.3 as published by the Free Software
13 ** Foundation and appearing in the file included in the packaging of
14 ** this file.
15 **
16 ** Other Usage
17 ** Alternatively, this file may be used in accordance with the terms
18 ** and conditions contained in a signed written agreement between you
19 ** and Nokia.
20 **
21 **
22 **
23 **
24 ** $QT_END_LICENSE$
25 **
26 ****************************************************************************/
27
28 /*!
29 \page qdeclarativenetwork.html
30 \inqmlmodule QtQuick 1
31 \ingroup qml-features
32 \previouspage {Dynamic Object Management in QML}{Dynamic Object Management}
33 \nextpage {QML Internationalization}{Internationalization}
34 \contentspage QML Features
35 \title Network Transparency
36
37 QML supports network transparency by using URLs (rather than file names) for all
38 references from a QML document to other content:
39
40 \qml
41 Image {
42     source: "http://www.example.com/images/logo.png"
43 }
44 \endqml
45
46 Since a \e relative URL is the same
47 as a relative file, development of QML on regular file systems remains simple:
48
49 \qml
50 Image {
51     source: "images/logo.png"
52 }
53 \endqml
54
55 Network transparency is supported throughout QML, for example:
56
57 \list
58 \o Fonts - the \c source property of FontLoader is a URL
59 \o WebViews - the \c url property of WebView (obviously!)
60 \endlist
61
62 Even QML types themselves can be on the network - if the \l {QML Viewer} is used to load
63 \tt http://example.com/mystuff/Hello.qml and that content refers to a type "World", the engine
64 will load \tt http://example.com/mystuff/qmldir and resolve the type just as it would for a local file.
65 For example if the qmldir file contains the line "World World.qml", it will load
66 \tt http://example.com/mystuff/World.qml
67 Any other resources that \tt Hello.qml referred to, usually by a relative URL, would
68 similarly be loaded from the network.
69
70
71 \section1 Relative vs. Absolute URLs
72
73 Whenever an object has a property of type URL (QUrl), assigning a string to that
74 property will actually assign an absolute URL - by resolving the string against
75 the URL of the document where the string is used.
76
77 For example, consider this content in \tt{http://example.com/mystuff/test.qml}:
78
79 \qml
80 Image {
81     source: "images/logo.png"
82 }
83 \endqml
84
85 The \l Image source property will be assigned \tt{http://example.com/mystuff/images/logo.png},
86 but while the QML is being developed, in say \tt C:\\User\\Fred\\Documents\\MyStuff\\test.qml, it will be assigned
87 \tt C:\\User\\Fred\\Documents\\MyStuff\\images\\logo.png.
88
89 If the string assigned to a URL is already an absolute URL, then "resolving" does
90 not change it and the URL is assigned directly.
91
92
93 \section1 Progressive Loading
94
95 Because of the declarative nature of QML and the asynchronous nature of network resources,
96 objects which reference network resource generally change state as the network resource loads.
97 For example, an Image with a network source will initially have
98 a \c width and \c height of 0, a \c status of \c Loading, and a \c progress of 0.0.
99 While the content loads, the \c progress will increase until
100 the content is fully loaded from the network,
101 at which point the \c width and \c height become the content size, the \c status becomes \c Ready, and the \c progress reaches 1.0.
102 Applications can bind to these changing states to provide visual progress indicators where appropriate, or simply
103 bind to the \c width and \c height as if the content was a local file, adapting as those bound values change.
104
105 Note that when objects reference local files they immediately have the \c Ready status, but applications wishing
106 to remain network transparent should not rely on this. Future versions of QML may also use asynchronous local file I/O
107 to improve performance.
108
109
110 \section1 Accessing Network Services
111
112 QML types such as XmlListModel, and JavaScript classes like XMLHttpRequest are intended
113 entirely for accessing network services, which usually respond with references to
114 content by URLs that can then be used directly in QML. For example, using these facilities
115 to access an on-line photography service would provide the QML application with URLs to
116 photographs, which can be directly set on an \l Image \c source property.
117
118 See the \tt examples/declarative/flickr for a real demonstration of this.
119
120
121 \section1 Configuring the Network Access Manager
122
123 All network access from QML is managed by a QNetworkAccessManager set on the QDeclarativeEngine which executes the QML.
124 By default, this is an unmodified Qt QNetworkAccessManager. You may set a different manager by
125 providing a QDeclarativeNetworkAccessManagerFactory and setting it via
126 QDeclarativeEngine::setNetworkAccessManagerFactory().
127 For example, the \l {QML Viewer} sets a QDeclarativeNetworkAccessManagerFactory which
128 creates QNetworkAccessManager that trusts HTTP Expiry headers to avoid network cache checks,
129 allows HTTP Pipelining, adds a persistent HTTP CookieJar, a simple disk cache, and supports proxy settings.
130
131
132 \section1 QRC Resources
133
134 One of the URL schemes built into Qt is the "qrc" scheme. This allows content to be compiled into
135 the executable using \l{The Qt Resource System}. Using this, an executable can reference QML content
136 that is compiled into the executable:
137
138 \code
139     QDeclarativeView *canvas = new QDeclarativeView;
140     canvas->setUrl(QUrl("qrc:/dial.qml"));
141 \endcode
142
143 The content itself can then use relative URLs, and so be transparently unaware that the content is
144 compiled into the executable.
145
146
147 \section1 Limitations
148
149 The \c import statement is only network transparent if it has an "as" clause.
150
151 More specifically:
152 \list
153 \o \c{import "dir"} only works on local file systems
154 \o \c{import libraryUri} only works on local file systems
155 \o \c{import "dir" as D} works network transparently
156 \o \c{import libraryUrl as U} works network transparently
157 \endlist
158
159
160 */