Skip to content

Instantly share code, notes, and snippets.

@brendan-w
Created June 9, 2016 01:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendan-w/9d9b94f1c2e427c6078655f92f51aa33 to your computer and use it in GitHub Desktop.
Save brendan-w/9d9b94f1c2e427c6078655f92f51aa33 to your computer and use it in GitHub Desktop.
Command line inspector for Qt's object hierarchy
#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