Qt 4.8
Classes | Functions
qdeclarativeerror.cpp File Reference
#include "qdeclarativeerror.h"
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
#include <QtCore/qstringlist.h>

Go to the source code of this file.

Classes

class  QDeclarativeErrorPrivate
 

Function Documentation

◆ operator<<()

QDebug operator<< ( QDebug  debug,
const QDeclarativeError error 
)
related

Definition at line 247 of file qdeclarativeerror.cpp.

248 {
249  debug << qPrintable(error.toString());
250 
251  QUrl url = error.url();
252 
253  if (error.line() > 0 && url.scheme() == QLatin1String("file")) {
254  QString file = url.toLocalFile();
255  QFile f(file);
256  if (f.open(QIODevice::ReadOnly)) {
257  QByteArray data = f.readAll();
259 #ifndef QT_NO_TEXTCODEC
260  stream.setCodec("UTF-8");
261 #endif
262  const QString code = stream.readAll();
263  const QStringList lines = code.split(QLatin1Char('\n'));
264 
265  if (lines.count() >= error.line()) {
266  const QString &line = lines.at(error.line() - 1);
267  debug << "\n " << qPrintable(line);
268 
269  if(error.column() > 0) {
270  int column = qMax(0, error.column() - 1);
271  column = qMin(column, line.length());
272 
273  QByteArray ind;
274  ind.reserve(column);
275  for (int i = 0; i < column; ++i) {
276  const QChar ch = line.at(i);
277  if (ch.isSpace())
278  ind.append(ch.unicode());
279  else
280  ind.append(' ');
281  }
282  ind.append('^');
283  debug << "\n " << ind.constData();
284  }
285  }
286  }
287  }
288  return debug;
289 }
QUrl url() const
Returns the url for the file that caused this error.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
QString toString() const
Returns the error as a human readable string.
static FILE * stream
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static const char * data(const QByteArray &arr)
int line() const
Returns the error line number.
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
The QTextStream class provides a convenient interface for reading and writing text.
Definition: qtextstream.h:73
int column() const
Returns the error column number.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
#define qPrintable(string)
Definition: qglobal.h:1750
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55