source: trunk/doc/src/declarative/network.qdoc@ 1036

Last change on this file since 1036 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

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