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 |
|
---|
32 | QML supports network transparency by using URLs (rather than file names) for all
|
---|
33 | references from a QML document to other content:
|
---|
34 |
|
---|
35 | \qml
|
---|
36 | Image {
|
---|
37 | source: "http://www.example.com/images/logo.png"
|
---|
38 | }
|
---|
39 | \endqml
|
---|
40 |
|
---|
41 | Since a \e relative URL is the same
|
---|
42 | as a relative file, development of QML on regular file systems remains simple:
|
---|
43 |
|
---|
44 | \qml
|
---|
45 | Image {
|
---|
46 | source: "images/logo.png"
|
---|
47 | }
|
---|
48 | \endqml
|
---|
49 |
|
---|
50 | Network 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 |
|
---|
57 | Even 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
|
---|
59 | will load \tt http://example.com/mystuff/qmldir and resolve the type just as it would for a local file.
|
---|
60 | For example if the qmldir file contains the line "World World.qml", it will load
|
---|
61 | \tt http://example.com/mystuff/World.qml
|
---|
62 | Any other resources that \tt Hello.qml referred to, usually by a relative URL, would
|
---|
63 | similarly be loaded from the network.
|
---|
64 |
|
---|
65 |
|
---|
66 | \section1 Relative vs. Absolute URLs
|
---|
67 |
|
---|
68 | Whenever an object has a property of type URL (QUrl), assigning a string to that
|
---|
69 | property will actually assign an absolute URL - by resolving the string against
|
---|
70 | the URL of the document where the string is used.
|
---|
71 |
|
---|
72 | For example, consider this content in \tt{http://example.com/mystuff/test.qml}:
|
---|
73 |
|
---|
74 | \qml
|
---|
75 | Image {
|
---|
76 | source: "images/logo.png"
|
---|
77 | }
|
---|
78 | \endqml
|
---|
79 |
|
---|
80 | The \l Image source property will be assigned \tt{http://example.com/mystuff/images/logo.png},
|
---|
81 | but 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 |
|
---|
84 | If the string assigned to a URL is already an absolute URL, then "resolving" does
|
---|
85 | not change it and the URL is assigned directly.
|
---|
86 |
|
---|
87 |
|
---|
88 | \section1 Progressive Loading
|
---|
89 |
|
---|
90 | Because of the declarative nature of QML and the asynchronous nature of network resources,
|
---|
91 | objects which reference network resource generally change state as the network resource loads.
|
---|
92 | For example, an Image with a network source will initially have
|
---|
93 | a \c width and \c height of 0, a \c status of \c Loading, and a \c progress of 0.0.
|
---|
94 | While the content loads, the \c progress will increase until
|
---|
95 | the content is fully loaded from the network,
|
---|
96 | 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.
|
---|
97 | Applications can bind to these changing states to provide visual progress indicators where appropriate, or simply
|
---|
98 | bind to the \c width and \c height as if the content was a local file, adapting as those bound values change.
|
---|
99 |
|
---|
100 | Note that when objects reference local files they immediately have the \c Ready status, but applications wishing
|
---|
101 | to remain network transparent should not rely on this. Future versions of QML may also use asynchronous local file I/O
|
---|
102 | to improve performance.
|
---|
103 |
|
---|
104 |
|
---|
105 | \section1 Accessing Network Services
|
---|
106 |
|
---|
107 | QML types such as XmlListModel, and JavaScript classes like XMLHttpRequest are intended
|
---|
108 | entirely for accessing network services, which usually respond with references to
|
---|
109 | content by URLs that can then be used directly in QML. For example, using these facilities
|
---|
110 | to access an on-line photography service would provide the QML application with URLs to
|
---|
111 | photographs, which can be directly set on an \l Image \c source property.
|
---|
112 |
|
---|
113 | See the \tt demos/declarative/flickr for a real demonstration of this.
|
---|
114 |
|
---|
115 |
|
---|
116 | \section1 Configuring the Network Access Manager
|
---|
117 |
|
---|
118 | All network access from QML is managed by a QNetworkAccessManager set on the QDeclarativeEngine which executes the QML.
|
---|
119 | By default, this is an unmodified Qt QNetworkAccessManager. You may set a different manager by
|
---|
120 | providing a QDeclarativeNetworkAccessManagerFactory and setting it via
|
---|
121 | QDeclarativeEngine::setNetworkAccessManagerFactory().
|
---|
122 | For example, the \l {QML Viewer} sets a QDeclarativeNetworkAccessManagerFactory which
|
---|
123 | creates QNetworkAccessManager that trusts HTTP Expiry headers to avoid network cache checks,
|
---|
124 | allows HTTP Pipelining, adds a persistent HTTP CookieJar, a simple disk cache, and supports proxy settings.
|
---|
125 |
|
---|
126 |
|
---|
127 | \section1 QRC Resources
|
---|
128 |
|
---|
129 | One of the URL schemes built into Qt is the "qrc" scheme. This allows content to be compiled into
|
---|
130 | the executable using \l{The Qt Resource System}. Using this, an executable can reference QML content
|
---|
131 | that is compiled into the executable:
|
---|
132 |
|
---|
133 | \code
|
---|
134 | QDeclarativeView *canvas = new QDeclarativeView;
|
---|
135 | canvas->setUrl(QUrl("qrc:/dial.qml"));
|
---|
136 | \endcode
|
---|
137 |
|
---|
138 | The content itself can then use relative URLs, and so be transparently unaware that the content is
|
---|
139 | compiled into the executable.
|
---|
140 |
|
---|
141 |
|
---|
142 | \section1 Limitations
|
---|
143 |
|
---|
144 | The \c import statement is only network transparent if it has an "as" clause.
|
---|
145 |
|
---|
146 | More 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 | */
|
---|