Created
June 9, 2016 01:14
-
-
Save brendan-w/9d9b94f1c2e427c6078655f92f51aa33 to your computer and use it in GitHub Desktop.
Command line inspector for Qt's object hierarchy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <QString> | |
#include <QObject> | |
#include <QDebug> | |
#ifndef SPACER | |
# define SPACER " " | |
#endif | |
static void print_qobject(QObject* o, int level) | |
{ | |
QString line; | |
while((level--) != 0) line += SPACER; | |
line += o->metaObject()->className(); | |
if(o->objectName().length() > 0) | |
line += " #" + o->objectName(); | |
qDebug() << line.toUtf8().constData(); | |
} | |
void inspect(QObject* o, int level=0) | |
{ | |
if(level == 0) print_qobject(o, level); | |
level++; | |
foreach(QObject* child, o->children()) | |
{ | |
print_qobject(child, level); | |
inspect(child, level); //recurse | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment