PDA

View Full Version : QObjectBrowser



magland
14th June 2007, 12:28
I put together a little Qt4 utility that conveniently allows inspection of a QObject's properties, signals, and slots during program execution. It even keeps a tally on how many times the various signals have been triggered. I guess its the idea of QtObjectInspector, but very lightweight...

Perhaps it's been done before, but I think it could be very nice for debugging.... and quite easy to use.

Usage: include the attached files in your project. Then just go:



QObjectBrowser *browser=new QObjectBrowser(pointer_to_my_widget);
browser.showNormal();


Anyone's welcome to fancy it up... but don't everybody start modifying the code at once! Tell me if you plan to add a feature or improve the look.

Enjoy!
JM

magland
15th June 2007, 16:11
I've added some features (attachment).

You can now see the child and parent objects for the given QObject, and double click to navigate to those widgets/objects. This way you only need to set up QObjectBrowser for your top level widget and then navigate down to debug your entire application...

Let me know if anyone finds this useful. I'll keep developing if I see there are interested users...

krawek
15th June 2007, 21:36
Hi,

I just did:

- Moved ui file from QDialog to QWidget
- Improved layout
- Sets "void" if the method type name is empty


I attached the patch and the project

magland
15th June 2007, 22:37
Thanks very much... looks great.:) Future contributions should take it up from krawek's version.

I think this could become quite a useful tool.... I envision being able to change the values of properties during run time - (for debugging purposes). Also helpful to see the structure of an application.

JM

magland
18th June 2007, 13:12
Okay, I've added a tree control, so you can see a hierarchical tree of all the widgets in your application. Click on a widget to see all the properties, signals, slots, etc.

This is convenient, because you don't need to attach to an initial QObject any more. Simply use the following anywhere in your application:



QObjectBrowser *browser=new QObjectBrowser;
browser->showNormal();


I've attached the project file.

Feedback?

http://www.math.upenn.edu/~jfm/objectbrowser_screenshot.PNG

magland
21st June 2007, 05:27
Twice the functionality!
Please download and give feedback ...

New features:
* Automatically updates application's widget/object hierarchy every 3 seconds -- safely deletes old widgets in real time as they are closed/deleted

* Click the "Browse Focus Widget" to see the properties/signals/slots for the widget with current input focus --- great for reminding you which widgets are which - or for discovering the widget structure for someone else's source code!

* Right click on a widget/object in the tree to get a popup menu -- allows to hide/show/focus any widget at any time --- have you ever wondered what the "Qt internal tablet widget" looks like - now you can find out.

* As before, you get a real time tally of triggered signals...

http://www.math.upenn.edu/~jfm/objectbrowser_screenshot2.png

fullmetalcoder
21st June 2007, 09:47
Just wondering how you guess the "base class"... AFAIK QTreeWidget can't be a base class because it inherits QTreeView, which itself inherits QAbstractItemView, which itself... Can you print informations about interfaces that would be implemented by an object? Is it possible to modify the behavior of the app by adding connections on runtime? Is it possible to force a signal to be triggered or a slot to be executed? I think those could prove useful when debugging an app...
Sounds quite interesting anyway... Keep up the good work :) Maybe you'll someday find a trick to hook QObjectBrowser to a running Qt app without being forced to recompile it... It would just be SOOOOOOOOO neat ;)

magland
21st June 2007, 13:47
Thanks for the encouragement fmc.


Just wondering how you guess the "base class"...

I use QMetaObject::superClass(). Maybe base class isn't the right word?


Can you print informations about interfaces that would be implemented by an object?

I can if that info is in QMetaObject... haven't figured that out yet


Is it possible to modify the behavior of the app by adding connections on runtime? Is it possible to force a signal to be triggered or a slot to be executed? I think those could prove useful when debugging an app...


Yes I'm planning to put that in at some point.


Sounds quite interesting anyway... Keep up the good work :) Maybe you'll someday find a trick to hook QObjectBrowser to a running Qt app without being forced to recompile it... It would just be SOOOOOOOOO neat ;)

Thanks... yes if anyone has an idea to hook up to an external application.... ;)

Angelo Moriconi
7th August 2007, 17:07
Hi,
I've just download the last attachment (21 June 2007).
I try to compile it using Visual Studio C++.NET.
Using the Qt Visual studio integration I generate a solution starting from the .pro file.
In this solution I found correctly the example project and the objectbrowser project.
I compile the objectbrowser project and a .dll file has generated inside the bin folder.
The .lib file (that must be used by the example project) is not generated.
So when I try to build the example I receive a link error:

fatal error LNK1181: cannot open input file 'objectbrowser.lib'

I don't understand why, but it seems that the integration has create a solution with some wrong settings.

I would like to use your utility to monitoring my applications :( But without the .lib file I cannot link against the .dll file.

Any suggestions ?

Best,

Angelo

magland
7th August 2007, 17:23
You could try to go to the src\src.pro and replace CONFIG = dll with CONFIG = staticlib... then reopen your project...

marcel
7th August 2007, 23:22
Hi,
I've just download the last attachment (21 June 2007).
I try to compile it using Visual Studio C++.NET.
Using the Qt Visual studio integration I generate a solution starting from the .pro file.
In this solution I found correctly the example project and the objectbrowser project.
I compile the objectbrowser project and a .dll file has generated inside the bin folder.
The .lib file (that must be used by the example project) is not generated.
So when I try to build the example I receive a link error:

fatal error LNK1181: cannot open input file 'objectbrowser.lib'

I don't understand why, but it seems that the integration has create a solution with some wrong settings.

I would like to use your utility to monitoring my applications :( But without the .lib file I cannot link against the .dll file.

Any suggestions ?

Best,

Angelo

On Windows, you have to explicitly export the classes using Q_DECL_EXPORT.
See this thread( the last posts ).
http://www.qtcentre.org/forum/f-newbie-4/t-project-with-a-dll-and-a-testprog-doesnt-compile-page2-7829.html

regards

AlanEzust
13th April 2011, 00:39
Hi, I just went through my version of this and made some small updates. I was going to upload it back to this page, but while it says I have attach permissions I can't figure out how to attach right now.
Here is a temporary link until I figure out how to upload it to this site.

http://lazarus.homelinux.net/objectbrowser.tar.gz

*** Modified by Alan Ezust in July 2010, April 2011
Requires Qt 4.6 due to use of QScopedPointer.
Builds on windows as a library exporting symbols.
Changes to naming conventions.
Added toggle-view action: QObjectBrowserAction
Made ObjectBrowser an embeddable widget instead of a main window.
Use alternate properties for objectname in tree view.

magland
14th April 2011, 20:24
Alan, that's great -- thanks for the link!

AlanEzust
14th June 2011, 17:46
The link above no longer is good, and I figured out how to attach files so here it is: