C++

qmake: shared libs without versioning and symlinks

Written by  on October 12, 2021

By default share libraries have a symlink and versioning. To avoid this, add to respective *.pro:

iwyu: fatal error: ‘stddef.h’ file not found

Written by  on September 8, 2021

Include-what-you-use and Qt are not friends. iwyu-support in QtCreator is requested for a while, nobody cares.
So I installed it via apt; set an override to make and reran the build-process on a cleaned project:

Result: more than fifty errors like “fatal error: ‘stddef.h’ file not found”.
Some said that clang is missing (because that header is part of the installed package, my clang was 12 – iwyu was built against 11).
So the solution is:

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

tl;dr:
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
:INTERNAL_DOCS = NO

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:

Edit:
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 😉