-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQmlStackTraceHelper.cpp
58 lines (52 loc) · 1.92 KB
/
QmlStackTraceHelper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/****************************************************************************
** Copyright (C) 2019 Klaralvdalens Datakonsult AB, a KDAB Group company, [email protected].
** Author: [email protected]
** All rights reserved.
**
** This file may be distributed and/or modified under the terms of the
** GNU Lesser General Public License version 3 as published by the
** Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
**
** You may even contact us at [email protected] for different licensing options.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** Contact [email protected] if any conditions of this licensing are not
** clear to you.
**
**********************************************************************/
#include <QString>
#include <QVector>
#include <QGuiApplication>
#include <QQuickWindow>
#include <QQmlContext>
#include <QQuickItem>
#include <QtQml/private/qqmlengine_p.h>
namespace KDAB {
QString qmlStackTrace(QV4::ExecutionEngine *engine)
{
QString result;
QVector<QV4::StackFrame> frames = engine->stackTrace(15);
for (auto &f : frames)
result += QStringLiteral(" %1 [%2:%3]\n").arg(f.function, f.source).arg(f.line);
return result;
}
void printQmlStackTraces()
{
auto windows = qApp->topLevelWindows();
for (QWindow *w : windows) {
if (auto qw = qobject_cast<QQuickWindow*>(w)) {
QQuickItem *item = qw->contentItem();
QQmlContext* context = QQmlEngine::contextForObject(item);
if (!context)
continue;
QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(context->engine());
QV4::ExecutionEngine *v4engine = enginePriv->v4engine();
qDebug() << "Stack trace for" << qw;
qDebug().noquote() << qmlStackTrace(v4engine);
qDebug() << "\n";
}
}
}
}