summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/parser/qdeclarativejslexer.cpp2
-rw-r--r--src/declarative/qml/qdeclarativecomponent.cpp11
-rw-r--r--src/declarative/qml/qdeclarativecompositetypemanager.cpp2
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp17
-rw-r--r--src/declarative/qml/qdeclarativecontext_p.h2
-rw-r--r--src/declarative/qml/qdeclarativeengine.cpp34
-rw-r--r--src/declarative/qml/qdeclarativeengine_p.h2
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug.cpp45
-rw-r--r--src/declarative/qml/qdeclarativeenginedebug_p.h11
-rw-r--r--src/declarative/qml/qdeclarativeimageprovider.cpp4
-rw-r--r--src/declarative/qml/qdeclarativeimport.cpp2
-rw-r--r--src/declarative/qml/qdeclarativescriptparser.cpp2
-rw-r--r--src/declarative/qml/qdeclarativeworkerscript.cpp1
-rw-r--r--src/declarative/qml/qdeclarativexmlhttprequest.cpp87
-rw-r--r--src/declarative/qml/qmetaobjectbuilder.cpp2
15 files changed, 173 insertions, 51 deletions
diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp
index 65a6af2..cd08658 100644
--- a/src/declarative/qml/parser/qdeclarativejslexer.cpp
+++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp
@@ -120,7 +120,7 @@ Lexer::~Lexer()
void Lexer::setCode(const QString &c, int lineno)
{
- errmsg = QString();
+ errmsg.clear();
yylineno = lineno;
yycolumn = 1;
restrKeyword = false;
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp
index 5f4a063..d2d1f19 100644
--- a/src/declarative/qml/qdeclarativecomponent.cpp
+++ b/src/declarative/qml/qdeclarativecomponent.cpp
@@ -54,6 +54,7 @@
#include "private/qdeclarativeglobal_p.h"
#include "private/qdeclarativescriptparser_p.h"
#include "private/qdeclarativedebugtrace_p.h"
+#include "private/qdeclarativeenginedebug_p.h"
#include <QStack>
#include <QStringList>
@@ -104,6 +105,7 @@ class QByteArray;
/*!
\qmlclass Component QDeclarativeComponent
+ \ingroup qml-utility-elements
\since 4.7
\brief The Component element encapsulates a QML component definition.
@@ -599,7 +601,7 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q
property, or else the object will not be visible.
Dynamically created instances can be deleted with the \c destroy() method.
- See \l {Dynamic Object Management} for more information.
+ See \l {Dynamic Object Management in QML} for more information.
*/
/*!
@@ -764,8 +766,11 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons
QObject *rv = begin(ctxt, ep, cc, start, count, &state, bindings);
- if (rv && !context->isInternal && ep->isDebugging)
- context->asQDeclarativeContextPrivate()->instances.append(rv);
+ if (ep->isDebugging && rv) {
+ if (!context->isInternal)
+ context->asQDeclarativeContextPrivate()->instances.append(rv);
+ QDeclarativeEngineDebugServer::instance()->objectCreated(engine, rv);
+ }
return rv;
}
diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
index 26b2a9b..2e77534 100644
--- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp
+++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp
@@ -544,7 +544,7 @@ int QDeclarativeCompositeTypeManager::resolveTypes(QDeclarativeCompositeTypeData
}
- foreach (QDeclarativeScriptParser::Import imp, unit->data.imports()) {
+ foreach (const QDeclarativeScriptParser::Import &imp, unit->data.imports()) {
QDeclarativeDirComponents qmldircomponentsnetwork;
if (imp.type == QDeclarativeScriptParser::Import::Script)
continue;
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index a58dc6c..a3b16d9 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -533,8 +533,21 @@ void QDeclarativeContextData::invalidate()
parent = 0;
}
-void QDeclarativeContextData::clearExpressions()
+void QDeclarativeContextData::clearContext()
{
+ if (engine) {
+ while (componentAttached) {
+ QDeclarativeComponentAttached *a = componentAttached;
+ componentAttached = a->next;
+ if (componentAttached) componentAttached->prev = &componentAttached;
+
+ a->next = 0;
+ a->prev = 0;
+
+ emit a->destruction();
+ }
+ }
+
QDeclarativeAbstractExpression *expression = expressions;
while (expression) {
QDeclarativeAbstractExpression *nextExpression = expression->m_nextExpression;
@@ -555,7 +568,7 @@ void QDeclarativeContextData::destroy()
if (engine) invalidate();
- clearExpressions();
+ clearContext();
while (contextObjects) {
QDeclarativeData *co = contextObjects;
diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h
index c5a039a..6c14feb 100644
--- a/src/declarative/qml/qdeclarativecontext_p.h
+++ b/src/declarative/qml/qdeclarativecontext_p.h
@@ -113,7 +113,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeContextData
public:
QDeclarativeContextData();
QDeclarativeContextData(QDeclarativeContext *);
- void clearExpressions();
+ void clearContext();
void destroy();
void invalidate();
diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp
index 3fe89a5..4d244c5 100644
--- a/src/declarative/qml/qdeclarativeengine.cpp
+++ b/src/declarative/qml/qdeclarativeengine.cpp
@@ -114,6 +114,7 @@ QT_BEGIN_NAMESPACE
/*!
\qmlclass QtObject QObject
+ \ingroup qml-utility-elements
\since 4.7
\brief The QtObject element is the most basic element in QML.
@@ -185,6 +186,7 @@ void QDeclarativeEnginePrivate::defineModule()
/*!
\qmlclass QML:Qt QDeclarativeEnginePrivate
+ \ingroup qml-utility-elements
\brief The QML global Qt object provides useful enums and functions from Qt.
\keyword QmlGlobalQtObject
@@ -241,7 +243,7 @@ The format specification is described at \l{QML:Qt::formatDateTime}{Qt.formatDat
\section1 Dynamic Object Creation
The following functions on the global object allow you to dynamically create QML
-items from files or strings. See \l{Dynamic Object Management} for an overview
+items from files or strings. See \l{Dynamic Object Management in QML} for an overview
of their use.
\list
@@ -436,8 +438,6 @@ void QDeclarativeEnginePrivate::clear(SimpleList<QDeclarativeParserStatus> &pss)
pss.clear();
}
-Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer);
-
void QDeclarativePrivate::qdeclarativeelement_destructor(QObject *o)
{
QObjectPrivate *p = QObjectPrivate::get(o);
@@ -479,9 +479,8 @@ void QDeclarativeEnginePrivate::init()
if (QCoreApplication::instance()->thread() == q->thread() &&
QDeclarativeEngineDebugServer::isDebuggingEnabled()) {
- qmlEngineDebugServer();
isDebugging = true;
- QDeclarativeEngineDebugServer::addEngine(q);
+ QDeclarativeEngineDebugServer::instance()->addEngine(q);
}
}
@@ -545,11 +544,11 @@ QDeclarativeEngine::~QDeclarativeEngine()
{
Q_D(QDeclarativeEngine);
if (d->isDebugging)
- QDeclarativeEngineDebugServer::remEngine(this);
+ QDeclarativeEngineDebugServer::instance()->remEngine(this);
}
/*! \fn void QDeclarativeEngine::quit()
- This signal is emitted when the QDeclarativeEngine quits.
+ This signal is emitted when the QML loaded by the engine would like to quit.
*/
/*! \fn void QDeclarativeEngine::warnings(const QList<QDeclarativeError> &warnings)
@@ -672,7 +671,7 @@ void QDeclarativeEngine::addImageProvider(const QString &providerId, QDeclarativ
{
Q_D(QDeclarativeEngine);
QMutexLocker locker(&d->mutex);
- d->imageProviders.insert(providerId, provider);
+ d->imageProviders.insert(providerId, QSharedPointer<QDeclarativeImageProvider>(provider));
}
/*!
@@ -682,7 +681,7 @@ QDeclarativeImageProvider *QDeclarativeEngine::imageProvider(const QString &prov
{
Q_D(const QDeclarativeEngine);
QMutexLocker locker(&d->mutex);
- return d->imageProviders.value(providerId);
+ return d->imageProviders.value(providerId).data();
}
/*!
@@ -696,13 +695,14 @@ void QDeclarativeEngine::removeImageProvider(const QString &providerId)
{
Q_D(QDeclarativeEngine);
QMutexLocker locker(&d->mutex);
- delete d->imageProviders.take(providerId);
+ d->imageProviders.take(providerId);
}
QDeclarativeImageProvider::ImageType QDeclarativeEnginePrivate::getImageProviderType(const QUrl &url)
{
QMutexLocker locker(&mutex);
- QDeclarativeImageProvider *provider = imageProviders.value(url.host());
+ QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host());
+ locker.unlock();
if (provider)
return provider->imageType();
return static_cast<QDeclarativeImageProvider::ImageType>(-1);
@@ -712,7 +712,8 @@ QImage QDeclarativeEnginePrivate::getImageFromProvider(const QUrl &url, QSize *s
{
QMutexLocker locker(&mutex);
QImage image;
- QDeclarativeImageProvider *provider = imageProviders.value(url.host());
+ QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host());
+ locker.unlock();
if (provider)
image = provider->requestImage(url.path().mid(1), size, req_size);
return image;
@@ -722,7 +723,8 @@ QPixmap QDeclarativeEnginePrivate::getPixmapFromProvider(const QUrl &url, QSize
{
QMutexLocker locker(&mutex);
QPixmap pixmap;
- QDeclarativeImageProvider *provider = imageProviders.value(url.host());
+ QSharedPointer<QDeclarativeImageProvider> provider = imageProviders.value(url.host());
+ locker.unlock();
if (provider)
pixmap = provider->requestPixmap(url.path().mid(1), size, req_size);
return pixmap;
@@ -1119,7 +1121,7 @@ For example:
\snippet doc/src/snippets/declarative/createComponent-simple.qml 0
-See \l {Dynamic Object Management} for more information on using this function.
+See \l {Dynamic Object Management in QML} for more information on using this function.
To create a QML object from an arbitrary string of QML (instead of a file),
use \l{QML:Qt::createQmlObject()}{Qt.createQmlObject()}.
@@ -1171,7 +1173,7 @@ Note that this function returns immediately, and therefore may not work if
the \a qml string loads new components (that is, external QML files that have not yet been loaded).
If this is the case, consider using \l{QML:Qt::createComponent()}{Qt.createComponent()} instead.
-See \l {Dynamic Object Management} for more information on using this function.
+See \l {Dynamic Object Management in QML} for more information on using this function.
*/
QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngine *engine)
@@ -2074,7 +2076,7 @@ void QDeclarativeEnginePrivate::registerCompositeType(QDeclarativeCompiledData *
QByteArray name = data->root->className();
QByteArray ptr = name + '*';
- QByteArray lst = "QDeclarativeListProperty<" + name + ">";
+ QByteArray lst = "QDeclarativeListProperty<" + name + '>';
int ptr_type = QMetaType::registerType(ptr.constData(), voidptr_destructor,
voidptr_constructor);
diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h
index 3b5dd5a..db2db35 100644
--- a/src/declarative/qml/qdeclarativeengine_p.h
+++ b/src/declarative/qml/qdeclarativeengine_p.h
@@ -232,7 +232,7 @@ public:
mutable QNetworkAccessManager *networkAccessManager;
mutable QDeclarativeNetworkAccessManagerFactory *networkAccessManagerFactory;
- QHash<QString,QDeclarativeImageProvider*> imageProviders;
+ QHash<QString,QSharedPointer<QDeclarativeImageProvider> > imageProviders;
QDeclarativeImageProvider::ImageType getImageProviderType(const QUrl &url);
QImage getImageFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
QPixmap getPixmapFromProvider(const QUrl &url, QSize *size, const QSize& req_size);
diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp
index 1837366..ed28185 100644
--- a/src/declarative/qml/qdeclarativeenginedebug.cpp
+++ b/src/declarative/qml/qdeclarativeenginedebug.cpp
@@ -58,7 +58,13 @@
QT_BEGIN_NAMESPACE
-QList<QDeclarativeEngine *> QDeclarativeEngineDebugServer::m_engines;
+Q_GLOBAL_STATIC(QDeclarativeEngineDebugServer, qmlEngineDebugServer);
+
+QDeclarativeEngineDebugServer *QDeclarativeEngineDebugServer::instance()
+{
+ return qmlEngineDebugServer();
+}
+
QDeclarativeEngineDebugServer::QDeclarativeEngineDebugServer(QObject *parent)
: QDeclarativeDebugService(QLatin1String("QDeclarativeEngine"), parent),
m_watch(new QDeclarativeWatcher(this))
@@ -182,7 +188,7 @@ QVariant QDeclarativeEngineDebugServer::valueContents(const QVariant &value) con
}
void QDeclarativeEngineDebugServer::buildObjectDump(QDataStream &message,
- QObject *object, bool recur)
+ QObject *object, bool recur, bool dumpProperties)
{
message << objectData(object);
@@ -209,6 +215,8 @@ void QDeclarativeEngineDebugServer::buildObjectDump(QDataStream &message,
continue;
QDeclarativeBoundSignal *signal = QDeclarativeBoundSignal::cast(child);
if (signal) {
+ if (!dumpProperties)
+ continue;
QDeclarativeObjectProperty prop;
prop.type = QDeclarativeObjectProperty::SignalProperty;
prop.hasNotifySignal = false;
@@ -229,12 +237,17 @@ void QDeclarativeEngineDebugServer::buildObjectDump(QDataStream &message,
fakeProperties << prop;
} else {
if (recur)
- buildObjectDump(message, child, recur);
+ buildObjectDump(message, child, recur, dumpProperties);
else
message << objectData(child);
}
}
+ if (!dumpProperties) {
+ message << 0;
+ return;
+ }
+
message << (object->metaObject()->propertyCount() + fakeProperties.count());
for (int ii = 0; ii < object->metaObject()->propertyCount(); ++ii)
@@ -257,8 +270,7 @@ void QDeclarativeEngineDebugServer::buildObjectList(QDataStream &message, QDecla
QDeclarativeContextData *child = p->childContexts;
while (child) {
- if (!child->isInternal)
- ++count;
+ ++count;
child = child->nextChild;
}
@@ -266,8 +278,7 @@ void QDeclarativeEngineDebugServer::buildObjectList(QDataStream &message, QDecla
child = p->childContexts;
while (child) {
- if (!child->isInternal)
- buildObjectList(message, child->asQDeclarativeContext());
+ buildObjectList(message, child->asQDeclarativeContext());
child = child->nextChild;
}
@@ -372,8 +383,9 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message)
int queryId;
int objectId;
bool recurse;
+ bool dumpProperties = true;
- ds >> queryId >> objectId >> recurse;
+ ds >> queryId >> objectId >> recurse >> dumpProperties;
QObject *object = QDeclarativeDebugService::objectForId(objectId);
@@ -382,7 +394,7 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message)
rs << QByteArray("FETCH_OBJECT_R") << queryId;
if (object)
- buildObjectDump(rs, object, recurse);
+ buildObjectDump(rs, object, recurse, dumpProperties);
sendMessage(reply);
} else if (type == "WATCH_OBJECT") {
@@ -592,4 +604,19 @@ void QDeclarativeEngineDebugServer::remEngine(QDeclarativeEngine *engine)
m_engines.removeAll(engine);
}
+void QDeclarativeEngineDebugServer::objectCreated(QDeclarativeEngine *engine, QObject *object)
+{
+ Q_ASSERT(engine);
+ Q_ASSERT(m_engines.contains(engine));
+
+ int engineId = QDeclarativeDebugService::idForObject(engine);
+ int objectId = QDeclarativeDebugService::idForObject(object);
+
+ QByteArray reply;
+ QDataStream rs(&reply, QIODevice::WriteOnly);
+
+ rs << QByteArray("OBJECT_CREATED") << engineId << objectId;
+ sendMessage(reply);
+}
+
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativeenginedebug_p.h b/src/declarative/qml/qdeclarativeenginedebug_p.h
index ea35b40..613f1fe 100644
--- a/src/declarative/qml/qdeclarativeenginedebug_p.h
+++ b/src/declarative/qml/qdeclarativeenginedebug_p.h
@@ -92,8 +92,11 @@ public:
bool hasNotifySignal;
};
- static void addEngine(QDeclarativeEngine *);
- static void remEngine(QDeclarativeEngine *);
+ void addEngine(QDeclarativeEngine *);
+ void remEngine(QDeclarativeEngine *);
+ void objectCreated(QDeclarativeEngine *, QObject *);
+
+ static QDeclarativeEngineDebugServer *instance();
protected:
virtual void messageReceived(const QByteArray &);
@@ -103,7 +106,7 @@ private Q_SLOTS:
private:
void buildObjectList(QDataStream &, QDeclarativeContext *);
- void buildObjectDump(QDataStream &, QObject *, bool);
+ void buildObjectDump(QDataStream &, QObject *, bool, bool);
QDeclarativeObjectData objectData(QObject *);
QDeclarativeObjectProperty propertyData(QObject *, int);
QVariant valueContents(const QVariant &defaultValue) const;
@@ -111,7 +114,7 @@ private:
void resetBinding(int objectId, const QString &propertyName);
void setMethodBody(int objectId, const QString &method, const QString &body);
- static QList<QDeclarativeEngine *> m_engines;
+ QList<QDeclarativeEngine *> m_engines;
QDeclarativeWatcher *m_watch;
};
Q_DECLARATIVE_EXPORT QDataStream &operator<<(QDataStream &, const QDeclarativeEngineDebugServer::QDeclarativeObjectData &);
diff --git a/src/declarative/qml/qdeclarativeimageprovider.cpp b/src/declarative/qml/qdeclarativeimageprovider.cpp
index ea68327..ef31be7 100644
--- a/src/declarative/qml/qdeclarativeimageprovider.cpp
+++ b/src/declarative/qml/qdeclarativeimageprovider.cpp
@@ -161,7 +161,9 @@ QDeclarativeImageProvider::QDeclarativeImageProvider(ImageType type)
}
/*!
- \internal
+ Destroys the QDeclarativeImageProvider
+
+ \note The destructor of your derived class need to be thread safe.
*/
QDeclarativeImageProvider::~QDeclarativeImageProvider()
{
diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp
index 8d81b34..5c21ebc 100644
--- a/src/declarative/qml/qdeclarativeimport.cpp
+++ b/src/declarative/qml/qdeclarativeimport.cpp
@@ -338,7 +338,7 @@ QString QDeclarativeImportsPrivate::resolvedUri(const QString &dir_arg, QDeclara
qSort(paths.begin(), paths.end(), greaterThan); // Ensure subdirs preceed their parents.
QString stableRelativePath = dir;
- foreach( QString path, paths) {
+ foreach(const QString &path, paths) {
if (dir.startsWith(path)) {
stableRelativePath = dir.mid(path.length()+1);
break;
diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp
index 0657f49..0b3b35f 100644
--- a/src/declarative/qml/qdeclarativescriptparser.cpp
+++ b/src/declarative/qml/qdeclarativescriptparser.cpp
@@ -543,7 +543,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
QString typemodifier;
if(node->typeModifier)
typemodifier = node->typeModifier->asString();
- if (typemodifier == QString()) {
+ if (typemodifier.isEmpty()) {
type = Object::DynamicProperty::Custom;
} else if(typemodifier == QLatin1String("list")) {
type = Object::DynamicProperty::CustomList;
diff --git a/src/declarative/qml/qdeclarativeworkerscript.cpp b/src/declarative/qml/qdeclarativeworkerscript.cpp
index a42f131..509ca6b 100644
--- a/src/declarative/qml/qdeclarativeworkerscript.cpp
+++ b/src/declarative/qml/qdeclarativeworkerscript.cpp
@@ -514,6 +514,7 @@ void QDeclarativeWorkerScriptEngine::run()
/*!
\qmlclass WorkerScript QDeclarativeWorkerScript
+ \ingroup qml-utility-elements
\brief The WorkerScript element enables the use of threads in QML.
Use WorkerScript to run operations in a new thread.
diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
index eb37dd8..301ea1d 100644
--- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp
+++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
@@ -967,8 +967,9 @@ public:
QScriptValue send(QScriptValue *me, const QByteArray &);
QScriptValue abort(QScriptValue *me);
- QString responseBody() const;
+ QString responseBody();
const QByteArray & rawResponseBody() const;
+ bool receivedXml() const;
private slots:
void downloadProgress(qint64);
void error(QNetworkReply::NetworkError);
@@ -991,6 +992,15 @@ private:
HeadersList m_headersList;
void fillHeadersList();
+ bool m_gotXml;
+ QByteArray m_mime;
+ QByteArray m_charset;
+ QTextCodec *m_textCodec;
+#ifndef QT_NO_TEXTCODEC
+ QTextCodec* findTextCodec() const;
+#endif
+ void readEncoding();
+
QScriptValue m_me; // Set to the data object while a send() is ongoing (to access the callback)
QScriptValue dispatchCallback(QScriptValue *me);
@@ -1008,7 +1018,7 @@ private:
QDeclarativeXMLHttpRequest::QDeclarativeXMLHttpRequest(QNetworkAccessManager *manager)
: m_state(Unsent), m_errorFlag(false), m_sendFlag(false),
- m_redirectCount(0), m_network(0), m_nam(manager)
+ m_redirectCount(0), m_gotXml(false), m_textCodec(0), m_network(0), m_nam(manager)
{
}
@@ -1278,6 +1288,7 @@ void QDeclarativeXMLHttpRequest::finished()
if (cbv.isError()) printError(cbv);
}
m_responseEntityBody.append(m_network->readAll());
+ readEncoding();
if (xhrDump()) {
qWarning().nospace() << "XMLHttpRequest: RESPONSE " << qPrintable(m_url.toString());
@@ -1303,15 +1314,72 @@ void QDeclarativeXMLHttpRequest::finished()
}
-QString QDeclarativeXMLHttpRequest::responseBody() const
+void QDeclarativeXMLHttpRequest::readEncoding()
+{
+ foreach (const HeaderPair &header, m_headersList) {
+ if (header.first == "content-type") {
+ int separatorIdx = header.second.indexOf(';');
+ if (separatorIdx == -1) {
+ m_mime == header.second;
+ } else {
+ m_mime = header.second.mid(0, separatorIdx);
+ int charsetIdx = header.second.indexOf("charset=");
+ if (charsetIdx != -1) {
+ charsetIdx += 8;
+ separatorIdx = header.second.indexOf(';', charsetIdx);
+ m_charset = header.second.mid(charsetIdx, separatorIdx >= 0 ? separatorIdx : header.second.length());
+ }
+ }
+ break;
+ }
+ }
+
+ if (m_mime.isEmpty() || m_mime == "text/xml" || m_mime == "application/xml" || m_mime.endsWith("+xml"))
+ m_gotXml = true;
+}
+
+bool QDeclarativeXMLHttpRequest::receivedXml() const
+{
+ return m_gotXml;
+}
+
+
+#ifndef QT_NO_TEXTCODEC
+QTextCodec* QDeclarativeXMLHttpRequest::findTextCodec() const
+{
+ QTextCodec *codec = 0;
+
+ if (!m_charset.isEmpty())
+ codec = QTextCodec::codecForName(m_charset);
+
+ if (!codec && m_gotXml) {
+ QXmlStreamReader reader(m_responseEntityBody);
+ reader.readNext();
+ codec = QTextCodec::codecForName(reader.documentEncoding().toString().toUtf8());
+ }
+
+ if (!codec && m_mime == "text/html")
+ codec = QTextCodec::codecForHtml(m_responseEntityBody, 0);
+
+ if (!codec)
+ codec = QTextCodec::codecForUtfText(m_responseEntityBody, 0);
+
+ if (!codec)
+ codec = QTextCodec::codecForName("UTF-8");
+ return codec;
+}
+#endif
+
+
+QString QDeclarativeXMLHttpRequest::responseBody()
{
- QXmlStreamReader reader(m_responseEntityBody);
- reader.readNext();
#ifndef QT_NO_TEXTCODEC
- QTextCodec *codec = QTextCodec::codecForName(reader.documentEncoding().toUtf8());
- if (codec)
- return codec->toUnicode(m_responseEntityBody);
+ if (!m_textCodec)
+ m_textCodec = findTextCodec();
+ if (m_textCodec)
+ return m_textCodec->toUnicode(m_responseEntityBody);
#endif
+
return QString::fromUtf8(m_responseEntityBody);
}
@@ -1572,7 +1640,8 @@ static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScri
if (!request)
THROW_REFERENCE("Not an XMLHttpRequest object");
- if (request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
+ if (!request->receivedXml() ||
+ request->readyState() != QDeclarativeXMLHttpRequest::Loading &&
request->readyState() != QDeclarativeXMLHttpRequest::Done)
return engine->nullValue();
else
diff --git a/src/declarative/qml/qmetaobjectbuilder.cpp b/src/declarative/qml/qmetaobjectbuilder.cpp
index 6e4d7b8..0954248 100644
--- a/src/declarative/qml/qmetaobjectbuilder.cpp
+++ b/src/declarative/qml/qmetaobjectbuilder.cpp
@@ -1142,7 +1142,7 @@ static QByteArray buildParameterNames
if (!parameterNames.isEmpty()) {
QByteArray names;
bool first = true;
- foreach (QByteArray name, parameterNames) {
+ foreach (const QByteArray &name, parameterNames) {
if (first)
first = false;
else