GammaRay – another debugger for Qt

Written by  on September 24, 2020

Small OpenSource-tool from KDAB which can be used to alter the runtime-state of Qt-based programs. I’ve just used it (so far) with Qt for C++ and wonder if it would work with PyQt as well (TODO).
Changed parameters, layouts, styles, sizes, values are immediately applied and helpful to fine-tune especially layouts. It is some sophisticate debugger. Of course, with gdb you can alter values as well, but this Qt-aware tool offers for certain types (or layouts) just valid entries and ranges!

Code can be found here: https://github.com/KDAB/GammaRay/wiki/Getting-GammaRay
Some more documentation can be found here: https://www.kdab.com/development-resources/qt-tools/gammaray/
Quick-start guide:
First of all: the Qt-version of the GammaRay and of the UUT (unit under test; the program) should match. If not, then runtime-issues up to crash are possible ๐Ÿ™‚

As said: almost everything can be influenced, so for a limited task, I’ll show how to alter some style of ‘Cullendula’. Let’s set for it nice blue outlines for each widget!

0. start Cullendula
1. start GammaRay (bin/gammaray.exe for Win)
2. attach GammaRay to Cullendula via selecting it [1] and then switching (if not done automatically) to the proper build-version & -type of Qt [2]

3. in the next window search for “stylesheet” (best done via the search-box)

4. Now insert for styleSheet: “QWidget { border : 2px solid blue}” (without quotation marks!) and confirm with . The changes are applied immediately.

The same workflow can be applied almost everywhere to manipulate other properties .. good luck.
It’s a quite useful tool for layout-debugging. Also the measurement-tool can help to fine-tune margins .. or discuss color-values with stakeholders ..

Qt6: preview is available and usable

Written by  on September 8, 2020

After reading this blog-entry https://www.qt.io/blog/qt-6.0-feature-freeze-milestone-reached I wanted to give it a try and see how much effort it would make to transition from Qt 5 (5.12 or 5.15) to 6.
Hands on-approach: installed Qt6 via the maintenance tool (1 hr and 39 GiByte later ..), took my Cullendula-app and added a new target within QtCreator 4.12.

First clean build with MSVC2019_64bit gave a weird warning about
qtmaind.lib(qtmain_win.cpp.obj) : warning LNK4099: PDB 'WinMain.pdb' was not found with 'qtmaind.lib(qtmain_win.cpp.obj)' or at 'C:\Users\husband-boy\Desktop\coding\Cullendula\debug\WinMain.pdb'; linking object as if no debug info
where I still found no solution. But it works. Not a single line of code had to be changed ๐Ÿ™‚ If anyone ever transitioned from 3 to 4 (big ugh), or 4 to 5 (small ugh), you know the pain.

Bravo, I am positively impressed. Nothing worse than stagnation.

tutorial: include-what-you-use for a cmake/mingw-build on win

Written by  on August 5, 2020

0. Get the latest prebuilt version for Win: version 0.8 (3 years old :/)
1. Put this somewhere into you CMakeLists.txt
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "C:\\include-what-you-use\\bin\\include-what-you-use.exe")
2. Enjoy the overflowing build-output for your legacy-project.

Read more…

Doxygen: how to make sure internal features are not exported to OnlineHelp and PDFs

Written by  on June 23, 2020

0. doxy-config file (most of the times names .doxy) should contain

1. Doxygen-blocks for classes should be wrapped with

/// @cond INTERNAL
/// @ingroup whateverGRP

/// This class does something.

/// @endcond

2. Maybe use the keyword ‘internal’ for its real purpose ๐Ÿ˜‰

Additional note: only use
for newlines in Doxygen in C#. Else prepare for:
Severity Code Description Project File Line Suppression State
Warning CS1570 XML comment has badly formed XML -- 'Expected an end tag for element 'myTag'.'"

tutorial: heob (heap profiler; memory leak analysis)

Written by  on June 17, 2020

Heob is an OSS project, short for ‘heap observer’.

How to configure and use?
0. The official documentation from Qt/QtCreator is – like always :’D – a bit sparse: https://doc.qt.io/qtcreator/creator-heob.html
1. Get it from: https://github.com/ssbssa/heob/releases (I’ll use here release 3.1 from July 2019) and extract to the directory of your choice. This directory has to be set later as configuration path.
If you use gcc/mingw, then make sure you’ve dwarf-stack enabled. Since I’m just using the MSVC, not much had to be done.
2. Inside QtCreator (I am using right now 4.12 from the Maintenance Installer) go to “Analyze > Heob” and configure it like this:

The floppydisk-icon can be saved to store ONE configuration.
I leave most of the time the tracing to simple, else time-critical processes can fail. The output-files should be named if you do several runs, which you want to compare or post-process. Most of the time it makes sense to start disabled, because else heob tracks already all the losses at start and this will delay the start.
3. As example, I’ve set Cullendula as UUT (unit under test).

Since heob was started disabled, the leak recording is off: Activate it by pressing ‘n’. If you resize the terminal, the last line can become invisible due to some glitch. So better leave the size of the window untouched!
4. Do your favorite workflow in the UUT. Then close/quit the UUT.
5. Depending on how much allocations were done, heob takes more (up to ten minutes!) or less time (seconds in the case of Cullendula) to evaluate the leaks.

The results are sorted in descending order. Expand the entries to check the stack-trace of the cause.
Some can be triggered by leaks in the underlying libraries (Qt .. I am lookin at you: https://bugreports.qt.io/browse/QTBUG-59621), some by your own buggy implementation.

Hint: the generated xml-report can be later loaded again in the results-tab. Or specify “-o leaks20200617.html” for an optically more pleasing result.

Find crappy Qt-includes

Written by  on February 18, 2020

Use this regular expression

to check for includes of the format

Test it here with regex101.com.

QDialogs receive NO close-event in case of closing via the ESC-key. Nice.

Written by  on February 7, 2020

At first this looked like a bug, but upon reading carefully the documentation and crawling the internet, I’ve noticed that this is
a) wanted behavior and b) I am not the first one stumbling over this issue.

So just override in the header the method for processing the QHideEvent:

And reimplement the base-class-call with the emission of a custom signal (or triggering custom functionality) for futher processing. Like:

Another way is to connect the QDialog’s finished-signal to your signal via DirectConnection. Less code than overriding.

qobjectdefs_impl.h:72:118: error: no type named ‘Car’ in ‘struct QtPrivate::List<>‘

Written by  on February 4, 2020

Bruh, wait, what?

After rebasing a bigger feature and solving all obvious conflicts, the new build threw an error like “no type names Car”. And I am currently not working in the automotive industry!
Issue was that a commit, on which was rebased, changed ‘old’ Qt4-signal-slot-syntax (with SIGNAL/SLOT keywords; the string-based connect) to the ‘new’ Qt5-version (typed and verifyable from the compiler). And one of the slots had a default parameter. This is not allowed, except you squish a lambda as intermediate layer.

A bit more insight: Qt-docs.

edit: One of the earlier error-messags also hinted out what could be the culprit, but “no type named Car” is more funny ๐Ÿ˜‰

QtCreator: add online-help if the SDK is not coming from an official package

Written by  on January 1, 2020


having some Qt-SDK without help files. Using help inside a browser is possible, but cumbersome. and local help would be nice for quick parameter-checks.

solution (edited):

Found also the official docu at: http://download.qt-project.org/online/qtsdkrepository/windows_x86/desktop/qt5_5121_src_doc_examples/qt.qt5.5121.doc/ as 7z-archive.

Then add it via QtCreator > Tools > Options > Help > Documentation > “add the QCH files”.

Qt: custom-class and specialities for QVariant and QSettings

Written by  on December 11, 2019

While implementing some custom-class (C++17; Qt5.12) some specialities became (painfully) noticeable.
The guide at the Qt-source is quite well written.

  • ctor, copy-ctor and dtor are all required and have to be public
  • add Q_DECLARE_METATYPE(CustomClass)
  • QDebug-stream-operator in case of simple debugging-messages
  • if the QVariant-version of the CustomClass shall be written to QSettings, then implement also the two streaming operators: << and >> (else crash with Assert “unable to save type”): howto