📜 ⬆️ ⬇️

GammaRay - a means of introspection Qt-applications

The Qt framework provides quite good development tools - the Qt Creator IDE included in it includes a designer, a debugger, a profiler and other handy things. Unfortunately, even with all this it is sometimes not very clear why the application at the moment looks like it looks like: something is not visible, something does not look like it was expected, somewhere the wrong font size or the wrong picture.

Some of these problems can be solved in Qt Designer, but only a part. Qt Designer has several significant flaws: firstly, it incorrectly displays the position of Qt Quick components in the case of active use of Javascript when calculating their coordinates and sizes, secondly, in the designer we see the state of only the “empty” form, without data loaded into it. In general, there is a lack of something like developer tools in any modern browser: so that you can see the entire tree of components, find the right one, see its position relative to others, properties, fix something on the fly, choose a color \ font \ size, see which handlers are hung for events, etc.

And such a tool in the world of Qt appeared! Meet - GammaRay , a means of application introspection on Qt. GammaRay understands what Qt is, what your Qt application consists of, how it interacts with components, how they look, how events are generated and processed, etc. Let's see what GammaRay can do.
')


In essence, GammaRay is not one, but about 20 different tools, assembled in one application. Each tool is placed on its tab. Not all tabs may be active. For example, the Quick Scenes tab is active only if the application uses Qt Quick components.

Assembly

There are no binaries for Windows. Sources here: https://github.com/KDAB/GammaRay . To build under Windows + Qt 5.4, I needed to correct the CMakeLists.txt file by adding the following lines to it with the paths to my folder with Qt 5.4:

set(Qt5Core_DIR "D:/Qt/5.4/msvc2010_opengl/lib/cmake/Qt5Core") set(Qt5_DIR "D:/Qt/5.4/msvc2010_opengl/lib/cmake/Qt5") set(QT_QMAKE_EXECUTABLE "D:/Qt/5.4/android_x86/bin/qmake.exe") 


Otherwise, everything is going as it is written in the instructions (for Windows + Visual Studio):
 mkdir build cd build cmake -G "NMake Makefiles" .. nmake nmake install 


Launch

Now you need to build some Qt-application, the examples from the standard Qt delivery will be fine. Next you need to run gammaray, passing it the parameter path to the executable of the application under control:

 gammaray.exe D:\Qt\Examples\Qt-5.4\quick\demos\build-stocqt-Desktop_Qt_5_4_0_MSVC2010_OpenGL_32bit-Debug\debug\stocqt.exe 


Quick Scenes Tab

I'll start with the most interesting tab for me - Quick Scenes. That it is the Qt-analogue of the very browser Developer Tools, about which I wrote above. In the upper left of the tab, we see the Qt Quick tree of components, and not in its “original” form, but with all the objects created on runtime.


We can select the desired object in the tree - and it will be highlighted in the preview at the bottom of the window.


We can view the properties of this object in the right part of the window, change them. Thus, it is convenient to select the size of elements, fonts, colors, to see how the text of different lengths will fit within the limits assigned to it.


We can call a particular component method. For example, for MouseArea we can generate a “click”, which will lead to a call to the processing logic.


The preview window has several modes and, by the way, is “bidirectional” - i.e. the actions performed in it affect not only the preview, but also the application itself.

In addition, we can enable such a convenient mode of displaying content, which makes it easier to understand the mutual arrangement of components.


Objects tab

Here all Qt-objects of your application are listed in general. Functional: listing properties, calling methods, viewing signal slots. It is a little difficult to find a specific object, but there is a filter, sometimes it helps.


Models tab

It should show the models used in the application (inherited from QAbstractListModel). In my case, the application crashed every time you open this tab. Probably, the unstable version of GammaRay came across (after all, it took directly from GitHub).


Timers tab

All application timers


Resources Tab

Allows you to view all Qt-application resources (images, sounds, shaders, QML-code) and export them if necessary. Not very useful thing when working with your application (you see the same thing in the resource tree in Qt Creator), but it can help in analyzing someone else's program.


Signals

Shows events generated by all Qt objects in the application. The interface is not very convenient yet (it is not very clear which instance of a particular type generated events, lack of grouping capabilities and the flexibility to search for the necessary objects). However, with a certain dexterity, it allows you to quickly see the sequence of events, so to speak, “grasp the overall picture.”


State machines

Visualization of finite automata. Shows the machine in general, the current state, the history of transitions between states - in general, very clearly.


The remaining tabs of GammaRay seemed to me less interesting, although you never know who needs: viewing fonts, locales, logs, meta-objects, meta-types, environment variables, component styles.

In general, GammaRay is a great utility that fits well with the Qt infrastructure and allows you to save a few minutes where you can really save them.

Source: https://habr.com/ru/post/258411/


All Articles