summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/animations/easing.qml2
-rw-r--r--examples/declarative/connections/connections.qml4
-rw-r--r--examples/declarative/listview/recipes.qml6
-rw-r--r--examples/declarative/parallax/qml/ParallaxView.qml4
-rw-r--r--examples/declarative/plugins/plugin.cpp5
-rw-r--r--examples/declarative/progressbar/progressbars.qml2
-rw-r--r--examples/declarative/scrollbar/display.qml4
-rw-r--r--examples/declarative/velocity/velocity.qml2
-rw-r--r--examples/declarative/webview/qdeclarative-in-html.qml4
-rw-r--r--examples/network/http/httpwindow.cpp129
-rw-r--r--examples/network/http/httpwindow.h23
-rw-r--r--examples/network/http/main.cpp1
-rw-r--r--examples/network/loopback/dialog.cpp10
13 files changed, 105 insertions, 91 deletions
diff --git a/examples/declarative/animations/easing.qml b/examples/declarative/animations/easing.qml
index a7ba1c5..8f2655e 100644
--- a/examples/declarative/animations/easing.qml
+++ b/examples/declarative/animations/easing.qml
@@ -89,7 +89,7 @@ Rectangle {
}
Flickable {
- anchors.fill: parent; viewportHeight: layout.height
+ anchors.fill: parent; contentHeight: layout.height
Column {
id: layout
anchors.left: parent.left; anchors.right: parent.right
diff --git a/examples/declarative/connections/connections.qml b/examples/declarative/connections/connections.qml
index c140017..4692343 100644
--- a/examples/declarative/connections/connections.qml
+++ b/examples/declarative/connections/connections.qml
@@ -22,6 +22,6 @@ Rectangle {
anchors { right: parent.right; bottom: parent.bottom; rightMargin: 10; bottomMargin: 10 }
}
- Connection { sender: leftButton; signal: "clicked()"; script: window.angle -= 90 }
- Connection { sender: rightButton; signal: "clicked()"; script: window.angle += 90 }
+ Connections { target: leftButton; onClicked: window.angle -= 90 }
+ Connections { target: rightButton; onClicked: window.angle += 90 }
}
diff --git a/examples/declarative/listview/recipes.qml b/examples/declarative/listview/recipes.qml
index f848be0..b76a9ab 100644
--- a/examples/declarative/listview/recipes.qml
+++ b/examples/declarative/listview/recipes.qml
@@ -81,7 +81,7 @@ Rectangle {
Flickable {
id: flick
anchors.top: methodTitle.bottom; anchors.bottom: parent.bottom
- width: parent.width; viewportHeight: methodText.height; clip: true
+ width: parent.width; contentHeight: methodText.height; clip: true
Text { id: methodText; text: method; wrap: true; width: details.width }
}
Image {
@@ -114,7 +114,7 @@ Rectangle {
// Make the detailed view fill the entire list area
PropertyChanges { target: wrapper; height: list.height }
// Move the list so that this item is at the top.
- PropertyChanges { target: wrapper.ListView.view; explicit: true; viewportY: wrapper.y }
+ PropertyChanges { target: wrapper.ListView.view; explicit: true; contentY: wrapper.y }
// Disallow flicking while we're in detailed view
PropertyChanges { target: wrapper.ListView.view; interactive: false }
}
@@ -124,7 +124,7 @@ Rectangle {
ParallelAnimation {
ColorAnimation { property: "color"; duration: 500 }
NumberAnimation {
- duration: 300; properties: "detailsOpacity,x,viewportY,height,width"
+ duration: 300; properties: "detailsOpacity,x,contentY,height,width"
}
}
}
diff --git a/examples/declarative/parallax/qml/ParallaxView.qml b/examples/declarative/parallax/qml/ParallaxView.qml
index 811891b..5e58100 100644
--- a/examples/declarative/parallax/qml/ParallaxView.qml
+++ b/examples/declarative/parallax/qml/ParallaxView.qml
@@ -10,8 +10,8 @@ Item {
Image {
id: background
fillMode: Image.TileHorizontally
- x: -list.viewportX / 2
- width: Math.max(list.viewportWidth, parent.width)
+ x: -list.contentX / 2
+ width: Math.max(list.contentWidth, parent.width)
}
ListView {
diff --git a/examples/declarative/plugins/plugin.cpp b/examples/declarative/plugins/plugin.cpp
index f6385d0..741f68a 100644
--- a/examples/declarative/plugins/plugin.cpp
+++ b/examples/declarative/plugins/plugin.cpp
@@ -144,11 +144,10 @@ class QExampleQmlPlugin : public QDeclarativeExtensionPlugin
{
Q_OBJECT
public:
- void initialize(QDeclarativeEngine *engine, const char *uri)
+ void registerTypes(const char *uri)
{
- Q_UNUSED(engine);
Q_ASSERT(uri == QLatin1String("com.nokia.TimeExample"));
- qmlRegisterType<Time>(uri, 1, 0, "Time", "Time");
+ qmlRegisterType<Time>(uri, 1, 0, "Time");
}
};
diff --git a/examples/declarative/progressbar/progressbars.qml b/examples/declarative/progressbar/progressbars.qml
index fdd4ca7..6530c3d 100644
--- a/examples/declarative/progressbar/progressbars.qml
+++ b/examples/declarative/progressbar/progressbars.qml
@@ -6,7 +6,7 @@ Rectangle {
width: 600; height: 405; color: "#edecec"
Flickable {
- anchors.fill: parent; viewportHeight: column.height + 20
+ anchors.fill: parent; contentHeight: column.height + 20
Column {
id: column; x: 10; y: 10; spacing: 10
Repeater {
diff --git a/examples/declarative/scrollbar/display.qml b/examples/declarative/scrollbar/display.qml
index a96db6e..84763d2 100644
--- a/examples/declarative/scrollbar/display.qml
+++ b/examples/declarative/scrollbar/display.qml
@@ -12,8 +12,8 @@ Rectangle {
source: "pics/niagara_falls.jpg"
asynchronous: true
}
- viewportWidth: picture.width
- viewportHeight: picture.height
+ contentWidth: picture.width
+ contentHeight: picture.height
// Only show the scrollbars when the view is moving.
states: [
State {
diff --git a/examples/declarative/velocity/velocity.qml b/examples/declarative/velocity/velocity.qml
index 50d69d8..0d1881e 100644
--- a/examples/declarative/velocity/velocity.qml
+++ b/examples/declarative/velocity/velocity.qml
@@ -96,7 +96,7 @@ Rectangle {
}
Flickable {
id: flickable
- anchors.fill: parent; viewportWidth: lay.width
+ anchors.fill: parent; contentWidth: lay.width
Row {
id: lay
Repeater {
diff --git a/examples/declarative/webview/qdeclarative-in-html.qml b/examples/declarative/webview/qdeclarative-in-html.qml
index a2f2f2a..77180ec 100644
--- a/examples/declarative/webview/qdeclarative-in-html.qml
+++ b/examples/declarative/webview/qdeclarative-in-html.qml
@@ -6,8 +6,8 @@ Rectangle {
Flickable {
width: parent.width
height: parent.height/2
- viewportWidth: web.width*web.scale
- viewportHeight: web.height*web.scale
+ contentWidth: web.width*web.scale
+ contentHeight: web.height*web.scale
WebView {
id: web
width: 250
diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp
index 95fc82f..ec7cd33 100644
--- a/examples/network/http/httpwindow.cpp
+++ b/examples/network/http/httpwindow.cpp
@@ -49,9 +49,9 @@ HttpWindow::HttpWindow(QWidget *parent)
: QDialog(parent)
{
#ifndef QT_NO_OPENSSL
- urlLineEdit = new QLineEdit("https://");
+ urlLineEdit = new QLineEdit("https://qt.nokia.com/");
#else
- urlLineEdit = new QLineEdit("http://");
+ urlLineEdit = new QLineEdit("http://qt.nokia.com/");
#endif
urlLabel = new QLabel(tr("&URL:"));
@@ -70,21 +70,14 @@ HttpWindow::HttpWindow(QWidget *parent)
progressDialog = new QProgressDialog(this);
- http = new QHttp(this);
-
connect(urlLineEdit, SIGNAL(textChanged(QString)),
this, SLOT(enableDownloadButton()));
- connect(http, SIGNAL(requestFinished(int,bool)),
- this, SLOT(httpRequestFinished(int,bool)));
- connect(http, SIGNAL(dataReadProgress(int,int)),
- this, SLOT(updateDataReadProgress(int,int)));
- connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)),
- this, SLOT(readResponseHeader(QHttpResponseHeader)));
- connect(http, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)),
- this, SLOT(slotAuthenticationRequired(QString,quint16,QAuthenticator*)));
+
+ connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*)));
#ifndef QT_NO_OPENSSL
- connect(http, SIGNAL(sslErrors(QList<QSslError>)),
- this, SLOT(sslErrors(QList<QSslError>)));
+ connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
+ this, SLOT(sslErrors(QNetworkReply*,QList<QSslError>)));
#endif
connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));
connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile()));
@@ -104,9 +97,21 @@ HttpWindow::HttpWindow(QWidget *parent)
urlLineEdit->setFocus();
}
+void HttpWindow::startRequest(QUrl url)
+{
+ reply = qnam.get(QNetworkRequest(url));
+ connect(reply, SIGNAL(finished()),
+ this, SLOT(httpFinished()));
+ connect(reply, SIGNAL(readyRead()),
+ this, SLOT(httpReadyRead()));
+ connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
+ this, SLOT(updateDataReadProgress(qint64,qint64)));
+}
+
void HttpWindow::downloadFile()
{
- QUrl url(urlLineEdit->text());
+ url = urlLineEdit->text();
+
QFileInfo fileInfo(url.path());
QString fileName = fileInfo.fileName();
if (fileName.isEmpty())
@@ -132,35 +137,26 @@ void HttpWindow::downloadFile()
return;
}
- QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
- http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
-
- if (!url.userName().isEmpty())
- http->setUser(url.userName(), url.password());
-
- httpRequestAborted = false;
- QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/");
- if (path.isEmpty())
- path = "/";
- httpGetId = http->get(path, file);
progressDialog->setWindowTitle(tr("HTTP"));
progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));
downloadButton->setEnabled(false);
+
+ // schedule the request
+ httpRequestAborted = false;
+ startRequest(url);
}
void HttpWindow::cancelDownload()
{
statusLabel->setText(tr("Download canceled."));
httpRequestAborted = true;
- http->abort();
+ reply->abort();
downloadButton->setEnabled(true);
}
-void HttpWindow::httpRequestFinished(int requestId, bool error)
+void HttpWindow::httpFinished()
{
- if (requestId != httpGetId)
- return;
if (httpRequestAborted) {
if (file) {
file->close();
@@ -168,54 +164,58 @@ void HttpWindow::httpRequestFinished(int requestId, bool error)
delete file;
file = 0;
}
-
+ reply->deleteLater();
progressDialog->hide();
return;
}
- if (requestId != httpGetId)
- return;
-
progressDialog->hide();
+ file->flush();
file->close();
- if (error) {
+
+ QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (reply->error()) {
file->remove();
QMessageBox::information(this, tr("HTTP"),
tr("Download failed: %1.")
- .arg(http->errorString()));
+ .arg(reply->errorString()));
+ downloadButton->setEnabled(true);
+ } else if (!redirectionTarget.isNull()) {
+ QUrl newUrl = url.resolved(redirectionTarget.toUrl());
+ if (QMessageBox::question(this, tr("HTTP"),
+ tr("Redirect to %1 ?").arg(newUrl.toString()),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
+ url = newUrl;
+ reply->deleteLater();
+ file->open(QIODevice::WriteOnly);
+ file->resize(0);
+ startRequest(url);
+ return;
+ }
} else {
QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName();
statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName));
+ downloadButton->setEnabled(true);
}
- downloadButton->setEnabled(true);
+ reply->deleteLater();
+ reply = 0;
delete file;
file = 0;
}
-void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader)
+void HttpWindow::httpReadyRead()
{
- switch (responseHeader.statusCode()) {
- case 200: // Ok
- case 301: // Moved Permanently
- case 302: // Found
- case 303: // See Other
- case 307: // Temporary Redirect
- // these are not error conditions
- break;
-
- default:
- QMessageBox::information(this, tr("HTTP"),
- tr("Download failed: %1.")
- .arg(responseHeader.reasonPhrase()));
- httpRequestAborted = true;
- progressDialog->hide();
- http->abort();
- }
+ // this slot gets called everytime the QNetworkReply has new data.
+ // We read all of its new data and write it into the file.
+ // That way we use less RAM than when reading it at the finished()
+ // signal of the QNetworkReply
+ if (file)
+ file->write(reply->readAll());
}
-void HttpWindow::updateDataReadProgress(int bytesRead, int totalBytes)
+void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes)
{
if (httpRequestAborted)
return;
@@ -229,14 +229,19 @@ void HttpWindow::enableDownloadButton()
downloadButton->setEnabled(!urlLineEdit->text().isEmpty());
}
-void HttpWindow::slotAuthenticationRequired(const QString &hostName, quint16, QAuthenticator *authenticator)
+void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator)
{
QDialog dlg;
Ui::Dialog ui;
ui.setupUi(&dlg);
dlg.adjustSize();
- ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(hostName));
-
+ ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host()));
+
+ // Did the URL have information? Fill the UI
+ // This is only relevant if the URL-supplied credentials were wrong
+ ui.userEdit->setText(url.userName());
+ ui.passwordEdit->setText(url.password());
+
if (dlg.exec() == QDialog::Accepted) {
authenticator->setUser(ui.userEdit->text());
authenticator->setPassword(ui.passwordEdit->text());
@@ -244,7 +249,7 @@ void HttpWindow::slotAuthenticationRequired(const QString &hostName, quint16, QA
}
#ifndef QT_NO_OPENSSL
-void HttpWindow::sslErrors(const QList<QSslError> &errors)
+void HttpWindow::sslErrors(QNetworkReply*,const QList<QSslError> &errors)
{
QString errorString;
foreach (const QSslError &error, errors) {
@@ -253,10 +258,10 @@ void HttpWindow::sslErrors(const QList<QSslError> &errors)
errorString += error.errorString();
}
- if (QMessageBox::warning(this, tr("HTTP Example"),
+ if (QMessageBox::warning(this, tr("HTTP"),
tr("One or more SSL errors has occurred: %1").arg(errorString),
QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) {
- http->ignoreSslErrors();
+ reply->ignoreSslErrors();
}
}
#endif
diff --git a/examples/network/http/httpwindow.h b/examples/network/http/httpwindow.h
index 9dca8a5..83898af 100644
--- a/examples/network/http/httpwindow.h
+++ b/examples/network/http/httpwindow.h
@@ -43,18 +43,21 @@
#define HTTPWINDOW_H
#include <QDialog>
+#include <QNetworkAccessManager>
+#include <QUrl>
QT_BEGIN_NAMESPACE
class QDialogButtonBox;
class QFile;
-class QHttp;
-class QHttpResponseHeader;
class QLabel;
class QLineEdit;
class QProgressDialog;
class QPushButton;
class QSslError;
class QAuthenticator;
+class QNetworkReply;
+
+
QT_END_NAMESPACE
class HttpWindow : public QDialog
@@ -64,16 +67,18 @@ class HttpWindow : public QDialog
public:
HttpWindow(QWidget *parent = 0);
+ void startRequest(QUrl url);
+
private slots:
void downloadFile();
void cancelDownload();
- void httpRequestFinished(int requestId, bool error);
- void readResponseHeader(const QHttpResponseHeader &responseHeader);
- void updateDataReadProgress(int bytesRead, int totalBytes);
+ void httpFinished();
+ void httpReadyRead();
+ void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
void enableDownloadButton();
- void slotAuthenticationRequired(const QString &, quint16, QAuthenticator *);
+ void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *);
#ifndef QT_NO_OPENSSL
- void sslErrors(const QList<QSslError> &errors);
+ void sslErrors(QNetworkReply*,const QList<QSslError> &errors);
#endif
private:
@@ -85,7 +90,9 @@ private:
QPushButton *quitButton;
QDialogButtonBox *buttonBox;
- QHttp *http;
+ QUrl url;
+ QNetworkAccessManager qnam;
+ QNetworkReply *reply;
QFile *file;
int httpGetId;
bool httpRequestAborted;
diff --git a/examples/network/http/main.cpp b/examples/network/http/main.cpp
index ecbe100..817b2be 100644
--- a/examples/network/http/main.cpp
+++ b/examples/network/http/main.cpp
@@ -46,7 +46,6 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- qWarning("The usage of QHttp is not recommended anymore, please use QNetworkAccessManager.");
HttpWindow httpWin;
httpWin.show();
return httpWin.exec();
diff --git a/examples/network/loopback/dialog.cpp b/examples/network/loopback/dialog.cpp
index 27cff31..b504e36 100644
--- a/examples/network/loopback/dialog.cpp
+++ b/examples/network/loopback/dialog.cpp
@@ -44,12 +44,12 @@
#include "dialog.h"
-#if !defined(Q_OS_WINCE)
+#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN)
static const int TotalBytes = 50 * 1024 * 1024;
#else
static const int TotalBytes = 5 * 1024 * 1024;
#endif
-static const int PayloadSize = 65536;
+static const int PayloadSize = 64 * 1024; // 64 KB
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
@@ -130,6 +130,7 @@ void Dialog::acceptConnection()
void Dialog::startTransfer()
{
+ // called when the TCP client connected to the loopback server
bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@'));
clientStatusLabel->setText(tr("Connected"));
}
@@ -155,8 +156,11 @@ void Dialog::updateServerProgress()
void Dialog::updateClientProgress(qint64 numBytes)
{
+ // callen when the TCP client has written some bytes
bytesWritten += (int)numBytes;
- if (bytesToWrite > 0)
+
+ // only write more if not finished and when the Qt write buffer is below a certain size.
+ if (bytesToWrite > 0 && tcpClient.bytesToWrite() <= 4*PayloadSize)
bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@'));
clientProgressBar->setMaximum(TotalBytes);