diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/generators/objectinstances.cpp | 18 | ||||
-rw-r--r-- | src/generators/objectinstances_p.h | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/generators/objectinstances.cpp b/src/generators/objectinstances.cpp index e781691..9fea31a 100644 --- a/src/generators/objectinstances.cpp +++ b/src/generators/objectinstances.cpp @@ -7,6 +7,7 @@ #include <QDateTime> #include <QDebug> #include <QFile> +#include <QGuiApplication> #include <QQuickItem> #include <QStringList> #include <private/qobject_p.h> @@ -145,6 +146,23 @@ void ObjectInstances::generate() } } +/*! + Returns the first instance of a QQuickWindow that can be found within the + same process. + + This is useful when you use the qml tool to instrument a pre-existing + unmodified QML file that has a top-level Window or Item: see + \c examples/objectInstancesTimer.qml +*/ +QQuickWindow *ObjectInstances::findQuickWindow() +{ + for (auto *win : qGuiApp->topLevelWindows()) { + if (auto *qwin = qobject_cast<QQuickWindow *>(win)) + return qwin; + } + return nullptr; +} + void ObjectInstances::writeDot(const QString &plainFilePath, const QObject *o) { QString filePath = plainFilePath + u".dot"_s; diff --git a/src/generators/objectinstances_p.h b/src/generators/objectinstances_p.h index 7630743..142d84e 100644 --- a/src/generators/objectinstances_p.h +++ b/src/generators/objectinstances_p.h @@ -6,6 +6,7 @@ #include <QFile> #include <QQmlEngine> +#include <QQuickWindow> QT_BEGIN_NAMESPACE @@ -44,6 +45,7 @@ public: void setRoot(QObject *newRoot); Q_INVOKABLE void generate(); + Q_INVOKABLE QQuickWindow *findQuickWindow(); ColorSource nodeColorSource() const; void setNodeColorSource(ColorSource newNodeColorSource); |