Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Toutes les fonctions  ·  Vues d'ensemble  · 

Network Transparency

QML supports network transparency by using URLs (rather than file names) for all references from a QML document to other content:

 Image {
     source: "http://www.example.com/images/logo.png"
 }

Since a relative URL is the same as a relative file, development of QML on regular file systems remains simple:

 Image {
     source: "images/logo.png"
 }

Network transparency is supported throughout QML, for example:

  • Fonts - the source property of FontLoader is a URL
  • WebViews - the url property of WebView (obviously!)

Even QML types themselves can be on the network - if the QML Viewer is used to load http://example.com/mystuff/Hello.qml and that content refers to a type "World", the engine will load http://example.com/mystuff/qmldir and resolve the type just as it would for a local file. For example if the qmldir file contains the line "World World.qml", it will load http://example.com/mystuff/World.qml Any other resources that Hello.qml referred to, usually by a relative URL, would similarly be loaded from the network.

Relative vs. Absolute URLs

Whenever an object has a property of type URL (QUrl), assigning a string to that property will actually assign an absolute URL - by resolving the string against the URL of the document where the string is used.

For example, consider this content in http://example.com/mystuff/test.qml:

 Image {
     source: "images/logo.png"
 }

The Image source property will be assigned http://example.com/mystuff/images/logo.png, but while the QML is being developed, in say C:\User\Fred\Documents\MyStuff\test.qml, it will be assigned C:\User\Fred\Documents\MyStuff\images\logo.png.

If the string assigned to a URL is already an absolute URL, then "resolving" does not change it and the URL is assigned directly.

Progressive Loading

Because of the declarative nature of QML and the asynchronous nature of network resources, objects which reference network resource generally change state as the network resource loads. For example, an Image with a network source will initially have a width and height of 0, a status of Loading, and a progress of 0.0. While the content loads, the progress will increase until the content is fully loaded from the network, at which point the width and height become the content size, the status becomes Ready, and the progress reaches 1.0. Applications can bind to these changing states to provide visual progress indicators where appropriate, or simply bind to the width and height as if the content was a local file, adapting as those bound values change.

Note that when objects reference local files they immediately have the Ready status, but applications wishing to remain network transparent should not rely on this. Future versions of QML may also use asynchronous local file I/O to improve performance.

Accessing Network Services

QML types such as XmlListModel, and JavaScript classes like XMLHttpRequest are intended entirely for accessing network services, which usually respond with references to content by URLs that can then be used directly in QML. For example, using these facilities to access an on-line photography service would provide the QML application with URLs to photographs, which can be directly set on an Image source property.

See the demos/declarative/flickr for a real demonstration of this.

Configuring the Network Access Manager

All network access from QML is managed by a QNetworkAccessManager set on the QDeclarativeEngine which executes the QML. By default, this is an unmodified Qt QNetworkAccessManager. You may set a different manager by providing a QDeclarativeNetworkAccessManagerFactory and setting it via QDeclarativeEngine::setNetworkAccessManagerFactory(). For example, the QML Viewer sets a QDeclarativeNetworkAccessManagerFactory which creates QNetworkAccessManager that trusts HTTP Expiry headers to avoid network cache checks, allows HTTP Pipelining, adds a persistent HTTP CookieJar, a simple disk cache, and supports proxy settings.

QRC Resources

One of the URL schemes built into Qt is the "qrc" scheme. This allows content to be compiled into the executable using The Qt Resource System. Using this, an executable can reference QML content that is compiled into the executable:

     QDeclarativeView *canvas = new QDeclarativeView;
     canvas->setUrl(QUrl("qrc:/dial.qml"));

The content itself can then use relative URLs, and so be transparently unaware that the content is compiled into the executable.

Limitations

The import statement is only network transparent if it has an "as" clause.

More specifically:

  • import "dir" only works on local file systems
  • import libraryUri only works on local file systems
  • import "dir" as D works network transparently
  • import libraryUrl as U works network transparently
Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 82
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Quarterly au hasard

Logo

Qt s'associe avec le nouvel OS MeeGo

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.7-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web