summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlengine.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-07-07 03:28:56 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-07-07 03:28:56 (GMT)
commitf0062920559dd44f5f463ea4c3fa2657fceb81fb (patch)
tree58fd70afedd518c45d9e76847c889b805b07eb7f /src/declarative/qml/qmlengine.cpp
parent5972bfc6adaa32e4b21eb31a224346f143cbc530 (diff)
downloadQt-f0062920559dd44f5f463ea4c3fa2657fceb81fb.zip
Qt-f0062920559dd44f5f463ea4c3fa2657fceb81fb.tar.gz
Qt-f0062920559dd44f5f463ea4c3fa2657fceb81fb.tar.bz2
Improve QmlComponent API
Having to use QUrl::fromLocalFile() is crummy. Add appropriate overloads the QmlComponent, and resolve relative paths against a "base url" set on the QmlEngine.
Diffstat (limited to 'src/declarative/qml/qmlengine.cpp')
-rw-r--r--src/declarative/qml/qmlengine.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 1342dec..d88d11f 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -638,6 +638,36 @@ QNetworkAccessManager *QmlEngine::networkAccessManager() const
}
/*!
+ Return the base URL for this engine. The base URL is only used to resolve
+ components when a relative URL is passed to the QmlComponent constructor.
+
+ If a base URL has not been explicitly set, this method returns the
+ application's current working directory.
+
+ \sa setBaseUrl()
+*/
+QUrl QmlEngine::baseUrl() const
+{
+ Q_D(const QmlEngine);
+ if (d->baseUrl.isEmpty()) {
+ return QUrl::fromLocalFile(QDir::currentPath() + QDir::separator());
+ } else {
+ return d->baseUrl;
+ }
+}
+
+/*!
+ Set the base URL for this engine to \a url.
+
+ \sa baseUrl()
+*/
+void QmlEngine::setBaseUrl(const QUrl &url)
+{
+ Q_D(QmlEngine);
+ d->baseUrl = url;
+}
+
+/*!
Returns the QmlContext for the \a object, or 0 if no context has been set.
When the QmlEngine instantiates a QObject, the context is set automatically.