diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-21 04:51:19 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-21 04:51:19 (GMT) |
commit | d363b2ed7517dbbc8a54c02d8b606f4b52b54047 (patch) | |
tree | cb005c991ccf33aa99b8faed04d75c8e47526519 /src/declarative | |
parent | e79202be457298c48b13eef4f8c35df186216aea (diff) | |
download | Qt-d363b2ed7517dbbc8a54c02d8b606f4b52b54047.zip Qt-d363b2ed7517dbbc8a54c02d8b606f4b52b54047.tar.gz Qt-d363b2ed7517dbbc8a54c02d8b606f4b52b54047.tar.bz2 |
Fix crash when QDeclarativeInfo objects are copied
Diffstat (limited to 'src/declarative')
-rw-r--r-- | src/declarative/qml/qdeclarativeinfo.cpp | 133 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeinfo.h | 26 |
2 files changed, 78 insertions, 81 deletions
diff --git a/src/declarative/qml/qdeclarativeinfo.cpp b/src/declarative/qml/qdeclarativeinfo.cpp index f6560a6..ffed14e 100644 --- a/src/declarative/qml/qdeclarativeinfo.cpp +++ b/src/declarative/qml/qdeclarativeinfo.cpp @@ -80,92 +80,97 @@ QT_BEGIN_NAMESPACE struct QDeclarativeInfoPrivate { + QDeclarativeInfoPrivate() : ref (1), object(0) {} + + int ref; const QObject *object; - QString *buffer; + QString buffer; QList<QDeclarativeError> errors; }; -QDeclarativeInfo::QDeclarativeInfo(const QObject *object) -: QDebug((*(QString **)&d) = new QString) +QDeclarativeInfo::QDeclarativeInfo(QDeclarativeInfoPrivate *p) +: QDebug(&p->buffer), d(p) { - QDeclarativeInfoPrivate *p = new QDeclarativeInfoPrivate; - p->buffer = (QString *)d; - d = p; - - d->object = object; nospace(); } -QDeclarativeInfo::QDeclarativeInfo(const QObject *object, const QList<QDeclarativeError> &errors) -: QDebug((*(QString **)&d) = new QString) +QDeclarativeInfo::QDeclarativeInfo(const QDeclarativeInfo &other) +: QDebug(other), d(other.d) { - 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(); + d->ref++; } 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); + if (0 == --d->ref) { + 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); + } } - d->buffer->prepend(QLatin1String("QML ") + typeName + QLatin1String(": ")); + error.setDescription(d->buffer); - 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); - } + errors.prepend(error); } - error.setDescription(*d->buffer); + QDeclarativeEnginePrivate::warning(engine, errors); - errors.prepend(error); + delete d; } +} - QDeclarativeEnginePrivate::warning(engine, errors); +QDeclarativeInfo qmlInfo(const QObject *me) +{ + QDeclarativeInfoPrivate *d = new QDeclarativeInfoPrivate; + d->object = me; + return QDeclarativeInfo(d); +} - delete d->buffer; - delete d; +QDeclarativeInfo qmlInfo(const QObject *me, const QDeclarativeError &error) +{ + QDeclarativeInfoPrivate *d = new QDeclarativeInfoPrivate; + d->object = me; + d->errors << error; + return QDeclarativeInfo(d); } +QDeclarativeInfo qmlInfo(const QObject *me, const QList<QDeclarativeError> &errors) +{ + QDeclarativeInfoPrivate *d = new QDeclarativeInfoPrivate; + d->object = me; + d->errors = errors; + return QDeclarativeInfo(d); +} + + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeinfo.h b/src/declarative/qml/qdeclarativeinfo.h index 3d5a111..82f44f2 100644 --- a/src/declarative/qml/qdeclarativeinfo.h +++ b/src/declarative/qml/qdeclarativeinfo.h @@ -56,9 +56,7 @@ 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(const QDeclarativeInfo &); ~QDeclarativeInfo(); inline QDeclarativeInfo &operator<<(QChar t) { QDebug::operator<<(t); return *this; } @@ -86,23 +84,17 @@ public: inline QDeclarativeInfo &operator<<(const QUrl &t) { static_cast<QDebug &>(*this) << t; return *this; } private: + friend QDeclarativeInfo qmlInfo(const QObject *me); + friend QDeclarativeInfo qmlInfo(const QObject *me, const QDeclarativeError &error); + friend QDeclarativeInfo qmlInfo(const QObject *me, const QList<QDeclarativeError> &errors); + + QDeclarativeInfo(QDeclarativeInfoPrivate *); QDeclarativeInfoPrivate *d; }; -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); -} +Q_DECLARATIVE_EXPORT QDeclarativeInfo qmlInfo(const QObject *me); +Q_DECLARATIVE_EXPORT QDeclarativeInfo qmlInfo(const QObject *me, const QDeclarativeError &error); +Q_DECLARATIVE_EXPORT QDeclarativeInfo qmlInfo(const QObject *me, const QList<QDeclarativeError> &errors); QT_END_NAMESPACE |