Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qqmlinfo.h"
5
6#include "qqmldata_p.h"
7#include "qqmlmetatype_p.h"
8#include "qqmlengine_p.h"
10
11#include <QCoreApplication>
12
14
37
46
146{
147public:
149 : ref (1)
150 , msgType(type)
151 , object(nullptr)
152 {}
153
154 int ref;
158 QList<QQmlError> errors;
159};
160
162: QDebug(&p->buffer), d(p)
163{
164 nospace();
165}
166
168: QDebug(other), d(other.d)
169{
170 d->ref++;
171}
172
174{
175 if (0 == --d->ref) {
176 QList<QQmlError> errors = d->errors;
177
178 QQmlEngine *engine = nullptr;
179
180 if (!d->buffer.isEmpty()) {
182 error.setMessageType(d->msgType);
183
184 QObject *object = const_cast<QObject *>(d->object);
185
186 if (object) {
187 // Some objects (e.g. like attached objects created in C++) won't have an associated engine,
188 // but we can still try to look for a parent object that does.
189 QObject *objectWithEngine = object;
190 while (objectWithEngine) {
191 engine = qmlEngine(objectWithEngine);
192 if (engine)
193 break;
194 objectWithEngine = objectWithEngine->parent();
195 }
196
197 if (!objectWithEngine || objectWithEngine == object) {
199 } else {
200 d->buffer.prepend(QLatin1String("QML ") + QQmlMetaType::prettyTypeName(objectWithEngine)
201 + QLatin1String(" (parent or ancestor of ") + QQmlMetaType::prettyTypeName(object) + QLatin1String("): "));
202 }
203
204 QQmlData *ddata = QQmlData::get(objectWithEngine ? objectWithEngine : object, false);
205 if (ddata && ddata->outerContext) {
206 error.setUrl(ddata->outerContext->url());
207 error.setLine(qmlConvertSourceCoordinate<quint16, int>(ddata->lineNumber));
208 error.setColumn(qmlConvertSourceCoordinate<quint16, int>(ddata->columnNumber));
209 }
210 }
211
212 error.setDescription(d->buffer);
213
214 errors.prepend(error);
215 }
216
218
219 delete d;
220 }
221}
222
223#define MESSAGE_FUNCS(FuncName, MessageLevel) \
224 QQmlInfo FuncName(const QObject *me) \
225 { \
226 QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \
227 d->object = me; \
228 return QQmlInfo(d); \
229 } \
230 QQmlInfo FuncName(const QObject *me, const QQmlError &error) \
231 { \
232 QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \
233 d->object = me; \
234 d->errors << error; \
235 return QQmlInfo(d); \
236 } \
237 QQmlInfo FuncName(const QObject *me, const QList<QQmlError> &errors) \
238 { \
239 QQmlInfoPrivate *d = new QQmlInfoPrivate(MessageLevel); \
240 d->object = me; \
241 d->errors = errors; \
242 return QQmlInfo(d); \
243 }
244
248
\inmodule QtCore
\inmodule QtCore
Definition qobject.h:103
static QQmlData * get(QObjectPrivate *priv, bool create)
Definition qqmldata_p.h:199
void warning(const QQmlError &)
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:18
QList< QQmlError > errors
Definition qqmlinfo.cpp:158
const QObject * object
Definition qqmlinfo.cpp:156
QQmlInfoPrivate(QtMsgType type)
Definition qqmlinfo.cpp:148
QtMsgType msgType
Definition qqmlinfo.cpp:155
\inmodule QtQml
Definition qqmlinfo.h:30
QQmlInfo(const QQmlInfo &)
Definition qqmlinfo.cpp:167
static QString prettyTypeName(const QObject *object)
Returns the pretty QML type name (e.g.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
QString & prepend(QChar c)
Definition qstring.h:478
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
QtMsgType
Definition qlogging.h:29
@ QtInfoMsg
Definition qlogging.h:34
@ QtWarningMsg
Definition qlogging.h:31
@ QtDebugMsg
Definition qlogging.h:30
GLuint object
[3]
GLenum GLuint buffer
GLenum type
GLint ref
GLfloat GLfloat p
[1]
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:80
#define MESSAGE_FUNCS(FuncName, MessageLevel)
Definition qqmlinfo.cpp:223
Q_QML_EXPORT QQmlInfo qmlDebug(const QObject *me)
Q_QML_EXPORT QQmlInfo qmlInfo(const QObject *me)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
QJSEngine engine
[0]