PSA: Enable KCrash for you application

Nicolas Fella nicolas.fella at gmx.de
Thu Aug 8 14:06:03 BST 2024


Hi,

TL;DR: Call KCrash::initialize() after setting up KAboutData

crash reporting via DrKonqi to Bugzilla and Sentry is powered by the
KCrash framework, which acts as the crash handler inside the application.

To install the crash handler you need to call KCrash::initialize() in
your application's main function. Since the crash handler relies on
information from KAboutData you should do it after the call to
KAboutData::setApplicationData(). For best results make sure to include
the application version in the about data.

You can verify that it is working correctly by doing "killall -SEGV
myapp" and checking that DrKonqi appears and lets you submit a report.

Why am I sending this now? Some background:

In KF5 linking against KF5::Crash would automatically install the crash
handler for your application even without the explicity
KCrash::initalize(). This approach had some caveats:

- It doesn't work when linking with -as-needed, which is the default in
some distributions

- Similarly it won't work with static builds

- It can result in the crash handler being installed for non-KDE apps
that happen to load KF5::Crash, e.g. via out platform plugins

For these reasons for KF6 we dropped this approach (see
https://invent.kde.org/frameworks/kcrash/-/merge_requests/51), meaning
one must explicitly opt into our crash handling. A large number of our
applications does that already, but there's also a significant number
that doesn't. Please check your applications for that.

Cheers

Nico



More information about the kde-devel mailing list