From 8c80dd6a9893c6e323ae69b651efd7b629b2714c Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 25 Jul 2014 18:29:19 +0200 Subject: QDeclarativeError::toString: improve handling of empty urls. "file::2:23: ..." is strange to read. Show ":2:23: ..." instead, by treating empty urls (including "file:") as unknown, and by still showing line and column numbers in such a case. This change makes it possible for QUrl::fromLocalFile("") to return an empty url rather than "file:", which this module was relying upon in the tests. Change-Id: Id6d8aaa73673283cb65cbd1316dca77f859a3f8f Reviewed-by: Friedemann Kleint --- src/declarative/qml/qdeclarativeerror.cpp | 12 +++++++----- src/declarative/qml/qdeclarativeinfo.cpp | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/declarative') diff --git a/src/declarative/qml/qdeclarativeerror.cpp b/src/declarative/qml/qdeclarativeerror.cpp index 64d43d70..2232b382 100644 --- a/src/declarative/qml/qdeclarativeerror.cpp +++ b/src/declarative/qml/qdeclarativeerror.cpp @@ -216,14 +216,16 @@ void QDeclarativeError::setColumn(int column) QString QDeclarativeError::toString() const { QString rv; - if (url().isEmpty()) { + QUrl u(url()); + if (u.isEmpty() || (u.isLocalFile() && u.path().isEmpty())) rv = QLatin1String(""); - } else if (line() != -1) { - rv = url().toString() + QLatin1Char(':') + QString::number(line()); + else + rv = u.toString(); + + if (line() > 0) { + rv += 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/qdeclarativeinfo.cpp b/src/declarative/qml/qdeclarativeinfo.cpp index 74905bc4..b762bf70 100644 --- a/src/declarative/qml/qdeclarativeinfo.cpp +++ b/src/declarative/qml/qdeclarativeinfo.cpp @@ -134,7 +134,7 @@ QDeclarativeInfo::~QDeclarativeInfo() d->buffer.prepend(QLatin1String("QML ") + typeName + QLatin1String(": ")); QDeclarativeData *ddata = QDeclarativeData::get(object, false); - if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) { + if (ddata && ddata->outerContext) { error.setUrl(ddata->outerContext->url); error.setLine(ddata->lineNumber); error.setColumn(ddata->columnNumber); -- cgit v1.2.3