diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-19 10:36:50 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-05-19 10:36:50 (GMT) |
commit | c9057924dfa5da4d18030720431a92d2593f85df (patch) | |
tree | 1cef0e0137e1d4bb796f0507b72e95ab30c96e20 /examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp | |
parent | de0858687898f6e0e54cce3f986779c7aa1a350e (diff) | |
parent | d395903e4d061a30117f7b925bdad41771a29067 (diff) | |
download | Qt-c9057924dfa5da4d18030720431a92d2593f85df.zip Qt-c9057924dfa5da4d18030720431a92d2593f85df.tar.gz Qt-c9057924dfa5da4d18030720431a92d2593f85df.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: (36 commits)
Doc improvements
Disable mouse-based selection in TextInput/TextEdit
Rename qml executable to qmlviewer
Don't crash if the target parent is destroyed.
Introduce a threaded interpreter for QML binding bytecode
Bug moved.
doc
doc
Remove image example (covered in class docs)
When changing Loader source, remove old item from scene immediately.
Add missing .qmlproject files
Fix folderlistmodel with qt namespace
Renaming "Qml Launcher" back to "QML Viewer"
Rename some examples: proxyviewer -> networkaccessmanagerfactory,
Regression fix for Loader anchors not working
Make Qt.include() work for js files that have '.pragma library'
doc fix
Improve docs for Qt.quit()
Prevent assignment of values (string, number, bool) to signal handlers.
Make sure strings are escaped when returned via asScript.
...
Diffstat (limited to 'examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp')
-rw-r--r-- | examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp b/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp new file mode 100644 index 0000000..4ecbb5c --- /dev/null +++ b/examples/declarative/cppextensions/networkaccessmanagerfactory/main.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QNetworkAccessManager> +#include <QNetworkProxy> + +#include <QDeclarativeEngine> +#include <QDeclarativeNetworkAccessManagerFactory> +#include <QDeclarativeView> + + +/* + This example illustrates using a QNetworkAccessManagerFactory to + create a QNetworkAccessManager with a proxy. + + Usage: + networkaccessmanagerfactory [-host <proxy> -port <port>] [file] +*/ + +static QString proxyHost; +static int proxyPort = 0; + +class MyNetworkAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory +{ +public: + virtual QNetworkAccessManager *create(QObject *parent); +}; + +QNetworkAccessManager *MyNetworkAccessManagerFactory::create(QObject *parent) +{ + QNetworkAccessManager *nam = new QNetworkAccessManager(parent); + if (!proxyHost.isEmpty()) { + qDebug() << "Created QNetworkAccessManager using proxy" << (proxyHost + ":" + QString::number(proxyPort)); + QNetworkProxy proxy(QNetworkProxy::HttpCachingProxy, proxyHost, proxyPort); + nam->setProxy(proxy); + } + + return nam; +} + +int main(int argc, char ** argv) +{ + QUrl source("qrc:view.qml"); + + QApplication app(argc, argv); + + for (int i = 1; i < argc; ++i) { + QString arg(argv[i]); + if (arg == "-host" && i < argc-1) { + proxyHost = argv[++i]; + } else if (arg == "-port" && i < argc-1) { + arg = argv[++i]; + proxyPort = arg.toInt(); + } else if (arg[0] != '-') { + source = QUrl::fromLocalFile(arg); + } else { + qWarning() << "Usage: networkaccessmanagerfactory [-host <proxy> -port <port>] [file]"; + exit(1); + } + } + + QDeclarativeView view; + view.engine()->setNetworkAccessManagerFactory(new MyNetworkAccessManagerFactory); + + view.setSource(source); + view.show(); + + return app.exec(); +} + |