diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-19 04:08:20 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-19 04:08:20 (GMT) |
commit | 7aedb72dea904981969c0a4a9e5a6b721381c5a9 (patch) | |
tree | 820f58eace02ec8e0e001ba7faf28af23c58296e /src/declarative/qml | |
parent | 118890afb8b0a56d702d0822891d6417665ab515 (diff) | |
download | Qt-7aedb72dea904981969c0a4a9e5a6b721381c5a9.zip Qt-7aedb72dea904981969c0a4a9e5a6b721381c5a9.tar.gz Qt-7aedb72dea904981969c0a4a9e5a6b721381c5a9.tar.bz2 |
Emit runtime warnings through QDeclarativeEngine
QTBUG-9726
Diffstat (limited to 'src/declarative/qml')
20 files changed, 244 insertions, 100 deletions
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 25492ac..d759427 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -210,8 +210,7 @@ void QDeclarativeBinding::update(QDeclarativePropertyPrivate::WriteFlags flags) } if (data->error.isValid()) { - if (!data->addError(ep)) - qWarning().nospace() << qPrintable(this->error().toString()); + if (!data->addError(ep)) ep->warning(this->error()); } else { data->removeError(); } diff --git a/src/declarative/qml/qdeclarativeboundsignal.cpp b/src/declarative/qml/qdeclarativeboundsignal.cpp index 8c7a977..00a93cc 100644 --- a/src/declarative/qml/qdeclarativeboundsignal.cpp +++ b/src/declarative/qml/qdeclarativeboundsignal.cpp @@ -179,7 +179,7 @@ int QDeclarativeBoundSignal::qt_metacall(QMetaObject::Call c, int id, void **a) if (m_expression && m_expression->engine()) { QDeclarativeExpressionPrivate::get(m_expression)->value(m_params); if (m_expression && m_expression->hasError()) - qWarning().nospace() << qPrintable(m_expression->error().toString()); + QDeclarativeEnginePrivate::warning(m_expression->engine(), m_expression->error()); } if (m_params) m_params->clearValues(); return -1; diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 6fdf706..4a47fc6 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -938,7 +938,7 @@ static void throwException(int id, QDeclarativeDelayedError *error, error->error.setColumn(-1); } if (!context->engine || !error->addError(QDeclarativeEnginePrivate::get(context->engine))) - qWarning() << error->error; + QDeclarativeEnginePrivate::warning(context->engine, error->error); } static void dumpInstruction(const Instr *instr) diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 065009a..cced7b1 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -1218,7 +1218,14 @@ bool QDeclarativeCompiler::buildComponent(QDeclarativeParser::Object *obj, bool QDeclarativeCompiler::buildScript(QDeclarativeParser::Object *obj, QDeclarativeParser::Object *script) { - qWarning().nospace() << qPrintable(output->url.toString()) << ":" << obj->location.start.line << ":" << obj->location.start.column << ": Script blocks have been deprecated. Support will be removed entirely shortly."; + { + QDeclarativeError warning; + warning.setUrl(output->url); + warning.setLine(obj->location.start.line); + warning.setColumn(obj->location.start.column); + warning.setDescription(tr("Script blocks have been deprecated. Support will be removed entirely shortly.")); + qWarning() << warning.toString(); + } Object::ScriptBlock scriptBlock; diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 3e4651c..c86f089 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -530,10 +530,8 @@ QScriptValue QDeclarativeComponent::createObject() { Q_D(QDeclarativeComponent); QDeclarativeContext* ctxt = creationContext(); - if(!ctxt){ - qWarning() << QLatin1String("createObject can only be used in QML"); + if(!ctxt) return QScriptValue(); - } QObject* ret = create(ctxt); if (!ret) return QScriptValue(); @@ -613,17 +611,17 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, cons { Q_Q(QDeclarativeComponent); if (!context) { - qWarning("QDeclarativeComponent::beginCreate(): Cannot create a component in a null context"); + qWarning("QDeclarativeComponent: Cannot create a component in a null context"); return 0; } if (!context->isValid()) { - qWarning("QDeclarativeComponent::beginCreate(): Cannot create a component in an invalid context"); + qWarning("QDeclarativeComponent: Cannot create a component in an invalid context"); return 0; } if (context->engine != engine) { - qWarning("QDeclarativeComponent::beginCreate(): Must create component in context from the same QDeclarativeEngine"); + qWarning("QDeclarativeComponent: Must create component in context from the same QDeclarativeEngine"); return 0; } @@ -766,7 +764,7 @@ void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePri enginePriv->inProgressCreations--; if (0 == enginePriv->inProgressCreations) { while (enginePriv->erroredBindings) { - qWarning().nospace() << qPrintable(enginePriv->erroredBindings->error.toString()); + enginePriv->warning(enginePriv->erroredBindings->error); enginePriv->erroredBindings->removeError(); } } diff --git a/src/declarative/qml/qdeclarativecomponent.h b/src/declarative/qml/qdeclarativecomponent.h index 6ee5070..526a319 100644 --- a/src/declarative/qml/qdeclarativecomponent.h +++ b/src/declarative/qml/qdeclarativecomponent.h @@ -99,8 +99,6 @@ public: virtual QObject *beginCreate(QDeclarativeContext *); virtual void completeCreate(); - Q_INVOKABLE QScriptValue createObject(); - void loadUrl(const QUrl &url); void setData(const QByteArray &, const QUrl &baseUrl); @@ -114,6 +112,7 @@ Q_SIGNALS: protected: QDeclarativeComponent(QDeclarativeComponentPrivate &dd, QObject* parent); + Q_INVOKABLE QScriptValue createObject(); private: QDeclarativeComponent(QDeclarativeEngine *, QDeclarativeCompiledData *, int, int, QObject *parent); diff --git a/src/declarative/qml/qdeclarativecompositetypemanager.cpp b/src/declarative/qml/qdeclarativecompositetypemanager.cpp index 133b71f..adeb7a5 100644 --- a/src/declarative/qml/qdeclarativecompositetypemanager.cpp +++ b/src/declarative/qml/qdeclarativecompositetypemanager.cpp @@ -341,7 +341,6 @@ static QString toLocalFileOrQrc(const QUrl& url) if (url.scheme() == QLatin1String("qrc")) { if (url.authority().isEmpty()) return QLatin1Char(':') + url.path(); - qWarning() << "Invalid url:" << url.toString() << "authority" << url.authority() << "not known."; return QString(); } return url.toLocalFile(); diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index 5288923..31430c7 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -660,7 +660,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object if (scriptEngine->hasUncaughtException()) { QDeclarativeError error; QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error); - qWarning().nospace() << qPrintable(error.toString()); + enginePriv->warning(error); } scriptEngine->popContext(); @@ -686,7 +686,7 @@ void QDeclarativeContextData::addImportedScript(const QDeclarativeParser::Object if (scriptEngine->hasUncaughtException()) { QDeclarativeError error; QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error); - qWarning().nospace() << qPrintable(error.toString()); + enginePriv->warning(error); } scriptEngine->popContext(); @@ -720,7 +720,7 @@ void QDeclarativeContextData::addScript(const QDeclarativeParser::Object::Script if (scriptEngine->hasUncaughtException()) { QDeclarativeError error; QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error); - qWarning().nospace() << qPrintable(error.toString()); + enginePriv->warning(error); } } diff --git a/src/declarative/qml/qdeclarativedirparser.cpp b/src/declarative/qml/qdeclarativedirparser.cpp index 1e3b37b..3e05853 100644 --- a/src/declarative/qml/qdeclarativedirparser.cpp +++ b/src/declarative/qml/qdeclarativedirparser.cpp @@ -170,10 +170,9 @@ bool QDeclarativeDirParser::parse() const int dotIndex = version.indexOf(QLatin1Char('.')); if (dotIndex == -1) { - qWarning() << "expected '.'"; // ### use reportError + reportError(lineNumber, -1, QLatin1String("expected '.'")); } else if (version.indexOf(QLatin1Char('.'), dotIndex + 1) != -1) { - qWarning() << "unexpected '.'"; // ### use reportError - + reportError(lineNumber, -1, QLatin1String("unexpected '.'")); } else { bool validVersionNumber = false; const int majorVersion = version.left(dotIndex).toInt(&validVersionNumber); @@ -189,8 +188,8 @@ bool QDeclarativeDirParser::parse() } } } else { - // ### use reportError - qWarning() << "a component declaration requires 3 arguments, but" << (sectionCount + 1) << "were provided"; + reportError(lineNumber, -1, + QString::fromUtf8("a component declaration requires 3 arguments, but %1 were provided").arg(sectionCount + 1)); } } diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 4dbd199..9cd6b3c 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -153,10 +153,10 @@ void QDeclarativeEnginePrivate::defineModule() QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) : captureProperties(false), rootContext(0), currentExpression(0), isDebugging(false), - contextClass(0), sharedContext(0), sharedScope(0), objectClass(0), valueTypeClass(0), - globalClass(0), cleanup(0), erroredBindings(0), inProgressCreations(0), - scriptEngine(this), workerScriptEngine(0), componentAttached(0), inBeginCreate(false), - networkAccessManager(0), networkAccessManagerFactory(0), + outputWarningsToStdErr(true), contextClass(0), sharedContext(0), sharedScope(0), + objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0), + inProgressCreations(0), scriptEngine(this), workerScriptEngine(0), componentAttached(0), + inBeginCreate(false), networkAccessManager(0), networkAccessManagerFactory(0), typeManager(e), uniqueId(1) { if (!qt_QmlQtModule_registered) { @@ -216,8 +216,6 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr offlineStoragePath = QDesktopServices::storageLocation(QDesktopServices::DataLocation).replace(QLatin1Char('/'), QDir::separator()) + QDir::separator() + QLatin1String("QML") + QDir::separator() + QLatin1String("OfflineStorage"); -#else - qWarning("offlineStoragePath is not set by default with QT_NO_DESKTOPSERVICES"); #endif qt_add_qmlxmlhttprequest(this); @@ -650,6 +648,34 @@ void QDeclarativeEngine::setBaseUrl(const QUrl &url) { Q_D(QDeclarativeEngine); d->baseUrl = url; +} + +/*! + Returns true if warning messages will be output to stderr in addition + to being emitted by the warnings() signal, otherwise false. + + The default value is true. +*/ +bool QDeclarativeEngine::outputWarningsToStandardError() const +{ + Q_D(const QDeclarativeEngine); + return d->outputWarningsToStdErr; +} + +/*! + Set whether warning messages will be output to stderr to \a enabled. + + If \a enabled is true, any warning messages generated by QML will be + output to stderr and emitted by the warnings() signal. If \a enabled + is false, on the warnings() signal will be emitted. This allows + applications to handle warning output themselves. + + The default value is true. +*/ +void QDeclarativeEngine::setOutputWarningsToStandardError(bool enabled) +{ + Q_D(QDeclarativeEngine); + d->outputWarningsToStdErr = enabled; } /*! @@ -777,9 +803,8 @@ void qmlExecuteDeferred(QObject *object) QDeclarativeComponentPrivate::complete(ep, &state); - if (!state.errors.isEmpty()) - qWarning() << state.errors; - + if (!state.errors.isEmpty()) + ep->warning(state.errors); } } @@ -1295,6 +1320,65 @@ void QDeclarativeEnginePrivate::sendQuit() emit q->quit(); } +static void dumpwarning(const QDeclarativeError &error) +{ + qWarning().nospace() << qPrintable(error.toString()); +} + +static void dumpwarning(const QList<QDeclarativeError> &errors) +{ + for (int ii = 0; ii < errors.count(); ++ii) + dumpwarning(errors.at(ii)); +} + +void QDeclarativeEnginePrivate::warning(const QDeclarativeError &error) +{ + Q_Q(QDeclarativeEngine); + q->warnings(QList<QDeclarativeError>() << error); + if (outputWarningsToStdErr) + dumpwarning(error); +} + +void QDeclarativeEnginePrivate::warning(const QList<QDeclarativeError> &errors) +{ + Q_Q(QDeclarativeEngine); + q->warnings(errors); + if (outputWarningsToStdErr) + dumpwarning(errors); +} + +void QDeclarativeEnginePrivate::warning(QDeclarativeEngine *engine, const QDeclarativeError &error) +{ + if (engine) + QDeclarativeEnginePrivate::get(engine)->warning(error); + else + dumpwarning(error); +} + +void QDeclarativeEnginePrivate::warning(QDeclarativeEngine *engine, const QList<QDeclarativeError> &error) +{ + if (engine) + QDeclarativeEnginePrivate::get(engine)->warning(error); + else + dumpwarning(error); +} + +void QDeclarativeEnginePrivate::warning(QDeclarativeEnginePrivate *engine, const QDeclarativeError &error) +{ + if (engine) + engine->warning(error); + else + dumpwarning(error); +} + +void QDeclarativeEnginePrivate::warning(QDeclarativeEnginePrivate *engine, const QList<QDeclarativeError> &error) +{ + if (engine) + engine->warning(error); + else + dumpwarning(error); +} + QScriptValue QDeclarativeEnginePrivate::quit(QScriptContext * /*ctxt*/, QScriptEngine *e) { QDeclarativeEnginePrivate *qe = get (e); @@ -1415,7 +1499,6 @@ static QString toLocalFileOrQrc(const QUrl& url) if (url.scheme() == QLatin1String("qrc")) { if (url.authority().isEmpty()) return QLatin1Char(':') + url.path(); - qWarning() << "Invalid url:" << url.toString() << "authority" << url.authority() << "not known."; return QString(); } return url.toLocalFile(); diff --git a/src/declarative/qml/qdeclarativeengine.h b/src/declarative/qml/qdeclarativeengine.h index 7b058ea..e161cd9 100644 --- a/src/declarative/qml/qdeclarativeengine.h +++ b/src/declarative/qml/qdeclarativeengine.h @@ -46,6 +46,7 @@ #include <QtCore/qobject.h> #include <QtCore/qmap.h> #include <QtScript/qscriptvalue.h> +#include <QtDeclarative/qdeclarativeerror.h> QT_BEGIN_HEADER @@ -102,6 +103,9 @@ public: QUrl baseUrl() const; void setBaseUrl(const QUrl &); + bool outputWarningsToStandardError() const; + void setOutputWarningsToStandardError(bool); + static QDeclarativeContext *contextForObject(const QObject *); static void setContextForObject(QObject *, QDeclarativeContext *); @@ -110,7 +114,8 @@ public: static ObjectOwnership objectOwnership(QObject *); Q_SIGNALS: - void quit (); + void quit(); + void warnings(const QList<QDeclarativeError> &warnings); private: Q_DECLARE_PRIVATE(QDeclarativeEngine) diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 43d329c..f6b9bcb 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -162,6 +162,8 @@ public: QDeclarativeExpression *currentExpression; bool isDebugging; + bool outputWarningsToStdErr; + struct ImportedNamespace; QDeclarativeContextScriptClass *contextClass; QDeclarativeContextData *sharedContext; @@ -312,6 +314,12 @@ public: QVariant scriptValueToVariant(const QScriptValue &, int hint = QVariant::Invalid); void sendQuit(); + void warning(const QDeclarativeError &); + void warning(const QList<QDeclarativeError> &); + static void warning(QDeclarativeEngine *, const QDeclarativeError &); + static void warning(QDeclarativeEngine *, const QList<QDeclarativeError> &); + static void warning(QDeclarativeEnginePrivate *, const QDeclarativeError &); + static void warning(QDeclarativeEnginePrivate *, const QList<QDeclarativeError> &); static QScriptValue qmlScriptObject(QObject*, QDeclarativeEngine*); diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 578733c..264fd8d 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -308,8 +308,6 @@ void QDeclarativeEngineDebugServer::messageReceived(const QByteArray &message) QByteArray type; ds >> type; - //qDebug() << "QDeclarativeEngineDebugServer::messageReceived()" << type; - if (type == "LIST_ENGINES") { int queryId; ds >> queryId; diff --git a/src/declarative/qml/qdeclarativeerror.cpp b/src/declarative/qml/qdeclarativeerror.cpp index 17e91e3..8717f56 100644 --- a/src/declarative/qml/qdeclarativeerror.cpp +++ b/src/declarative/qml/qdeclarativeerror.cpp @@ -216,9 +216,15 @@ void QDeclarativeError::setColumn(int column) QString QDeclarativeError::toString() const { QString rv; - rv = url().toString() + QLatin1Char(':') + QString::number(line()); - if(column() != -1) - rv += QLatin1Char(':') + QString::number(column()); + if (url().isEmpty()) { + rv = QLatin1String("<Unknown File>"); + } else if (line() != -1) { + rv = url().toString() + QLatin1Char(':') + QString::number(line()); + if(column() != -1) + rv += QLatin1Char(':') + QString::number(column()); + } else { + rv = url().toString(); + } rv += QLatin1String(": ") + description(); diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index 05240a2..8b5a62f 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -695,14 +695,13 @@ void QDeclarativeExpressionPrivate::updateGuards(const QPODVector<QDeclarativeEn if (!outputWarningHeader) { outputWarningHeader = true; qWarning() << "QDeclarativeExpression: Expression" << q->expression() - << "depends on non-NOTIFYable properties:"; + << "depends on non-NOTIFYable properties:"; } const QMetaObject *metaObj = property.object->metaObject(); QMetaProperty metaProp = metaObj->property(property.coreIndex); - qWarning().nospace() << " " << metaObj->className() - << "::" << metaProp.name(); + qWarning().nospace() << " " << metaObj->className() << "::" << metaProp.name(); } } } diff --git a/src/declarative/qml/qdeclarativeinfo.cpp b/src/declarative/qml/qdeclarativeinfo.cpp index 0a4352f..f6560a6 100644 --- a/src/declarative/qml/qdeclarativeinfo.cpp +++ b/src/declarative/qml/qdeclarativeinfo.cpp @@ -45,6 +45,7 @@ #include "qdeclarativecontext.h" #include "private/qdeclarativecontext_p.h" #include "private/qdeclarativemetatype_p.h" +#include "private/qdeclarativeengine_p.h" #include <QCoreApplication> @@ -77,52 +78,94 @@ QT_BEGIN_NAMESPACE \endcode */ +struct QDeclarativeInfoPrivate +{ + const QObject *object; + QString *buffer; + QList<QDeclarativeError> errors; +}; + QDeclarativeInfo::QDeclarativeInfo(const QObject *object) -: QDebug(QtWarningMsg) +: QDebug((*(QString **)&d) = new QString) { - QString pos = QLatin1String("QML"); - if (object) { - pos += QLatin1Char(' '); - - QString typeName; - QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject()); - if (type) { - typeName = QLatin1String(type->qmlTypeName()); - int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); - if (lastSlash != -1) - typeName = typeName.mid(lastSlash+1); - } else { - typeName = QString::fromUtf8(object->metaObject()->className()); - int marker = typeName.indexOf(QLatin1String("_QMLTYPE_")); - if (marker != -1) - typeName = typeName.left(marker); - } + QDeclarativeInfoPrivate *p = new QDeclarativeInfoPrivate; + p->buffer = (QString *)d; + d = p; - pos += typeName; - } - QDeclarativeData *ddata = object?QDeclarativeData::get(object):0; - pos += QLatin1String(" ("); - if (ddata) { - if (ddata->outerContext && !ddata->outerContext->url.isEmpty()) { - pos += ddata->outerContext->url.toString(); - pos += QLatin1Char(':'); - pos += QString::number(ddata->lineNumber); - pos += QLatin1Char(':'); - pos += QString::number(ddata->columnNumber); - } else { - pos += QCoreApplication::translate("QDeclarativeInfo","unknown location"); - } - } else { - pos += QCoreApplication::translate("QDeclarativeInfo","unknown location"); - } - pos += QLatin1Char(')'); - *this << pos; + d->object = object; nospace(); } -QDeclarativeInfo::~QDeclarativeInfo() +QDeclarativeInfo::QDeclarativeInfo(const QObject *object, const QList<QDeclarativeError> &errors) +: QDebug((*(QString **)&d) = new QString) { + QDeclarativeInfoPrivate *p = new QDeclarativeInfoPrivate; + p->buffer = (QString *)d; + d = p; + + d->object = object; + d->errors = errors; + nospace(); } +QDeclarativeInfo::QDeclarativeInfo(const QObject *object, const QDeclarativeError &error) +: QDebug((*(QString **)&d) = new QString) +{ + QDeclarativeInfoPrivate *p = new QDeclarativeInfoPrivate; + p->buffer = (QString *)d; + d = p; + + d->object = object; + d->errors << error; + nospace(); +} + +QDeclarativeInfo::~QDeclarativeInfo() +{ + QList<QDeclarativeError> errors = d->errors; + + QDeclarativeEngine *engine = 0; + + if (!d->buffer->isEmpty()) { + QDeclarativeError error; + + QObject *object = const_cast<QObject *>(d->object); + + if (object) { + engine = qmlEngine(d->object); + QString typeName; + QDeclarativeType *type = QDeclarativeMetaType::qmlType(object->metaObject()); + if (type) { + typeName = QLatin1String(type->qmlTypeName()); + int lastSlash = typeName.lastIndexOf(QLatin1Char('/')); + if (lastSlash != -1) + typeName = typeName.mid(lastSlash+1); + } else { + typeName = QString::fromUtf8(object->metaObject()->className()); + int marker = typeName.indexOf(QLatin1String("_QMLTYPE_")); + if (marker != -1) + typeName = typeName.left(marker); + } + + d->buffer->prepend(QLatin1String("QML ") + typeName + QLatin1String(": ")); + + QDeclarativeData *ddata = QDeclarativeData::get(object, false); + if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) { + error.setUrl(ddata->outerContext->url); + error.setLine(ddata->lineNumber); + error.setColumn(ddata->columnNumber); + } + } + + error.setDescription(*d->buffer); + + errors.prepend(error); + } + + QDeclarativeEnginePrivate::warning(engine, errors); + + delete d->buffer; + delete d; +} QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeinfo.h b/src/declarative/qml/qdeclarativeinfo.h index 8f69f73..36de7b1 100644 --- a/src/declarative/qml/qdeclarativeinfo.h +++ b/src/declarative/qml/qdeclarativeinfo.h @@ -43,6 +43,7 @@ #define QDECLARATIVEINFO_H #include <QtCore/qdebug.h> +#include <QtDeclarative/qdeclarativeerror.h> QT_BEGIN_HEADER @@ -50,10 +51,13 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) +class QDeclarativeInfoPrivate; class Q_DECLARATIVE_EXPORT QDeclarativeInfo : public QDebug { public: QDeclarativeInfo(const QObject *); + QDeclarativeInfo(const QObject *, const QDeclarativeError &); + QDeclarativeInfo(const QObject *, const QList<QDeclarativeError> &); ~QDeclarativeInfo(); inline QDeclarativeInfo &operator<<(QChar t) { QDebug::operator<<(t); return *this; } @@ -78,6 +82,9 @@ public: inline QDeclarativeInfo &operator<<(const void * t) { QDebug::operator<<(t); return *this; } inline QDeclarativeInfo &operator<<(QTextStreamFunction f) { QDebug::operator<<(f); return *this; } inline QDeclarativeInfo &operator<<(QTextStreamManipulator m) { QDebug::operator<<(m); return *this; } + +private: + QDeclarativeInfoPrivate *d; }; Q_DECLARATIVE_EXPORT inline QDeclarativeInfo qmlInfo(const QObject *me) @@ -85,6 +92,16 @@ Q_DECLARATIVE_EXPORT inline QDeclarativeInfo qmlInfo(const QObject *me) return QDeclarativeInfo(me); } +Q_DECLARATIVE_EXPORT inline QDeclarativeInfo qmlInfo(const QObject *me, const QDeclarativeError &error) +{ + return QDeclarativeInfo(me, error); +} + +Q_DECLARATIVE_EXPORT inline QDeclarativeInfo qmlInfo(const QObject *me, const QList<QDeclarativeError> &errors) +{ + return QDeclarativeInfo(me, errors); +} + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/declarative/qml/qdeclarativemetatype.cpp b/src/declarative/qml/qdeclarativemetatype.cpp index 7b71608..d41bd43 100644 --- a/src/declarative/qml/qdeclarativemetatype.cpp +++ b/src/declarative/qml/qdeclarativemetatype.cpp @@ -403,10 +403,8 @@ int QDeclarativeType::index() const int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterInterface &interface) { - if (interface.version > 0) { - qWarning("Cannot mix incompatible QML versions."); - return -1; - } + if (interface.version > 0) + qFatal("qmlRegisterType(): Cannot mix incompatible QML versions."); QWriteLocker lock(metaTypeDataLock()); QDeclarativeMetaTypeData *data = metaTypeData(); @@ -437,7 +435,7 @@ int QDeclarativePrivate::registerType(const QDeclarativePrivate::RegisterType &t if (type.elementName) { for (int ii = 0; type.elementName[ii]; ++ii) { if (!isalnum(type.elementName[ii])) { - qWarning("QDeclarativeMetaType: Invalid QML element name %s", type.elementName); + qWarning("qmlRegisterType(): Invalid QML element name \"%s\"", type.elementName); return -1; } } diff --git a/src/declarative/qml/qdeclarativeproxymetaobject.cpp b/src/declarative/qml/qdeclarativeproxymetaobject.cpp index fe0dce7..c2dce0a 100644 --- a/src/declarative/qml/qdeclarativeproxymetaobject.cpp +++ b/src/declarative/qml/qdeclarativeproxymetaobject.cpp @@ -41,17 +41,11 @@ #include "private/qdeclarativeproxymetaobject_p.h" -#include <QDebug> - QT_BEGIN_NAMESPACE QDeclarativeProxyMetaObject::QDeclarativeProxyMetaObject(QObject *obj, QList<ProxyData> *mList) : metaObjects(mList), proxies(0), parent(0), object(obj) { -#ifdef QDECLARATIVEPROXYMETAOBJECT_DEBUG - qWarning() << "QDeclarativeProxyMetaObject" << obj->metaObject()->className(); -#endif - *static_cast<QMetaObject *>(this) = *metaObjects->first().metaObject; QObjectPrivate *op = QObjectPrivate::get(obj); @@ -59,14 +53,6 @@ QDeclarativeProxyMetaObject::QDeclarativeProxyMetaObject(QObject *obj, QList<Pro parent = static_cast<QAbstractDynamicMetaObject*>(op->metaObject); op->metaObject = this; - -#ifdef QDECLARATIVEPROXYMETAOBJECT_DEBUG - const QMetaObject *mo = obj->metaObject(); - while(mo) { - qWarning() << " " << mo->className(); - mo = mo->superClass(); - } -#endif } QDeclarativeProxyMetaObject::~QDeclarativeProxyMetaObject() diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp index be2a1a7..b7e1832 100644 --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp @@ -1305,7 +1305,7 @@ void QDeclarativeXMLHttpRequest::printError(const QScriptValue& sv) { QDeclarativeError error; QDeclarativeExpressionPrivate::exceptionToError(sv.engine(), error); - qWarning().nospace() << qPrintable(error.toString()); + QDeclarativeEnginePrivate::warning(QDeclarativeEnginePrivate::get(sv.engine()), error); } void QDeclarativeXMLHttpRequest::destroyNetwork() |