Professional Documents
Culture Documents
Who am I?
Senior Software Engineer at Qt Software / Nokia Degrees in Engineering and an MBA Almost 2 years with the company Part of the Core Team
Work mostly with Networking, I/O, IPC, Threading, Tool Classes
Agenda
Background and rationale The Qt Network Access API The API in use Whats coming in Qt 4.5
Agenda
Background and rationale The Qt Network Access API The API in use Whats coming in Qt 4.5
Fragile
Easy to break
QHttp http; http.setHost(trolltech.com); int id1 = http.get(/); int id2 = http.get(/qtdevdays2008); connect(&http, SIGNAL(requestFinished(int,bool)), ...);
10
11
12
Agenda
Background and rationale The Qt Network Access API The API in use Whats coming in Qt 4.5
13
QNetworkRequest
QNetworkReply
QNetworkAccessManager
14
QNetworkRequest
Represents one request to be sent Main component: one URL Meta-data to the request:
HTTP headers SSL options Settings controlling behaviour
15
QNetworkReply
Read-only sequential-access QIODevice Data of the reply Meta-data:
URL Request associated HTTP headers and status Encryption status Error conditions
16
QNetworkReply (cont.)
Already open, but not finished yet Emits readyRead() when data arrives Emits finished() when done Emits error() if problem occurs Progress signals: downloadProgress() and uploadProgress()
17
QNetworkAccessManager
Operations supported:
HEAD obtain status GET download PUT upload POST HTTP-only
18
QNetworkAccessManager (cont.)
Manages request queue Centralises settings
Cookie Jar Proxy More in 4.5
Caches previous authentication successes Keeps connections open for some time
19
Cookies
Documentation defines as:
Cookies are small bits of information that stateless protocols like HTTP use to maintain some persistent information across requests.
One class: QNetworkCookie Does the parsing for you Recreates the raw form
20
21
22
23
QNetworkReply is abstract
Implement pure virtuals Emit readyRead() and other signals
24
Agenda
Background and rationale The Qt Network Access API The API in use Whats coming in Qt 4.5
25
26
27
Download() private slots:{ void finished(QNetworkReply *reply) connect(&manager, SIGNAL(finished(QNetworkReply*)), { reply->deleteLater(); SLOT(finished(QNetworkReply*))); emit done(reply->url(), reply->readAll()); } }
signals: void done(const QUrl &url, const QByteArray &data); };
29
QByteArray &data);
private slots: void finished(QNetworkReply *reply) { reply->deleteLater(); emit done(reply->url(), reply->readAll()); } signals: void done(const QUrl &url, const QByteArray &data); };
31
QNetworkAccessManager manager; public: Download() { connect(&manager, SIGNAL(finished(QNetworkReply*)), SLOT(finished(QNetworkReply*))); } void download(const QUrl &url) { manager.get(url); } private slots: void finished(QNetworkReply *reply) { reply->deleteLater(); emit done(reply->url(), reply->readAll()); } signals: void done(const QUrl &url, const QByteArray &data);
32
33
34
37
Synchronous downloading
No waitFor functions you must use the event loop
QByteArray synchronousDownload(const QNetworkRequest &request) { QNetworkReply *reply = manager.get(request); QEventLoop loop; connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); return reply->readAll(); }
38
Agenda
Background and rationale The Qt Network Access API The API in use Whats coming in Qt 4.5
39
40
Data caching
Problematic:
Network transfers are costly Therefore, we should avoid re-transferring
41
In a web browser
Default: PreferNetwork Reload button: AlwaysNetwork Offline browsing: AlwaysCache
42
Caching on disk
Public class: QNetworkDiskCache Sample implementation of data caching Saves all data to one directory on disk Controls cache size Should work from multiple processes...
43
Proxy factory
Problematic:
Different destinations accessed via different proxies Support for Proxy Auto Configuration (PAC) scripts
One single proxy for all requests doesnt cut it... New abstract class: QNetworkProxyFactory Integrated with QNetworkAccessManager:
setProxyFactory(QNetworkProxyFactory *)
44
Request
Proxy factory
45
JavaScript
46
47
Agenda
Summary
48
Summary
Qt Network Access is very powerful Easily extensible
49
Appendix
Extra slides
51