KCrash 5.109.0
Typedefs | Enumerations | Functions
KCrash Namespace Reference

This namespace contains functions to handle crashes. More...

Typedefs

typedef QFlags< CrashFlagCrashFlags
 Stores a combination of #CrashFlag values.
 
typedef void(* HandlerType) (int)
 Typedef for a pointer to a crash handler function.
 

Enumerations

enum  CrashFlag { KeepFDs = 1 , SaferDialog = 2 , AlwaysDirectly , AutoRestart = 8 }
 Options to determine how the default crash handler should behave. More...
 

Functions

HandlerType crashHandler ()
 Returns the installed crash handler.
 
void defaultCrashHandler (int signal)
 The default crash handler.
 
HandlerType emergencySaveFunction ()
 Returns the currently set emergency save function.
 
void initialize ()
 Initialize KCrash.
 
bool isDrKonqiEnabled ()
 Returns true if DrKonqi is set to be launched from the crash handler or false otherwise.
 
void setCrashHandler (HandlerType handler=defaultCrashHandler)
 Install a function to be called when a crash occurs.
 
void setDrKonqiEnabled (bool enabled)
 Enables or disables launching DrKonqi from the crash handler.
 
void setEmergencySaveFunction (HandlerType saveFunction=nullptr)
 Installs a function which should try to save the application's data.
 
void setErrorMessage (const QString &message)
 Allows providing information to be included in the bug report.
 
void setFlags (KCrash::CrashFlags flags)
 Set options to determine how the default crash handler should behave.
 

Detailed Description

This namespace contains functions to handle crashes.

It allows you to set a crash handler function that will be called when your application crashes and also provides a default crash handler that implements the following functionality:

Note
All the above features are optional and you need to enable them explicitly. By default, the defaultCrashHandler() will not do anything. However, if you are using KApplication, it will by default enable launching DrKonqi on crashes, unless the –nocrashhandler argument was passed on the command line or the environment variable KDE_DEBUG is set to any value.

Typedef Documentation

◆ CrashFlags

typedef QFlags< CrashFlag > KCrash::CrashFlags

Stores a combination of #CrashFlag values.

◆ HandlerType

typedef void(* KCrash::HandlerType) (int)

Typedef for a pointer to a crash handler function.

The function's argument is the number of the signal.

Enumeration Type Documentation

◆ CrashFlag

Options to determine how the default crash handler should behave.

See also
CrashFlags
Enumerator
KeepFDs 

don't close all file descriptors immediately

SaferDialog 

start DrKonqi without arbitrary disk access

AlwaysDirectly 

never try to to start DrKonqi via kdeinit. Use fork() and exec() instead.

Deprecated:
This is now the default, and does not need to be set.
AutoRestart 

autorestart this application. Only sensible for KUniqueApplications.

Since
4.1.

Function Documentation

◆ crashHandler()

HandlerType KCrash::crashHandler ( )

Returns the installed crash handler.

Returns
the crash handler

◆ defaultCrashHandler()

void KCrash::defaultCrashHandler ( int  signal)

The default crash handler.

Do not call this function directly. Instead, use setCrashHandler() to set it as your application's crash handler.

Parameters
signalthe signal number
Note
If you implement your own crash handler, you will have to call this function from your implementation if you want to use the features of this namespace.

◆ emergencySaveFunction()

HandlerType KCrash::emergencySaveFunction ( )

Returns the currently set emergency save function.

Returns
the emergency save function

◆ initialize()

void KCrash::initialize ( )

Initialize KCrash.

This does nothing if $KDE_DEBUG is set.

Call this in your main() to ensure that the crash handler is always launched.

Since
5.15

◆ isDrKonqiEnabled()

bool KCrash::isDrKonqiEnabled ( )

Returns true if DrKonqi is set to be launched from the crash handler or false otherwise.

Since
4.5

◆ setCrashHandler()

void KCrash::setCrashHandler ( HandlerType  handler = defaultCrashHandler)

Install a function to be called when a crash occurs.

A crash occurs when one of the following signals is caught: SIGSEGV, SIGBUS, SIGFPE, SIGILL, SIGABRT.

Parameters
handlerthis can be one of:
  • null, in which case signal catching is disabled (by setting the signal handler for the crash signals to SIG_DFL)
  • a user defined function in the form: static (if in a class) void myCrashHandler(int);
  • if handler is omitted, the default crash handler is installed
Note
If you use setDrKonqiEnabled(true), setEmergencySaveFunction(myfunc) or setFlags(AutoRestart), you do not need to call this function explicitly. The default crash handler is automatically installed by those functions if needed. However, if you set a custom crash handler, those functions will not change it.

◆ setDrKonqiEnabled()

void KCrash::setDrKonqiEnabled ( bool  enabled)

Enables or disables launching DrKonqi from the crash handler.

By default, launching DrKonqi is enabled when QCoreApplication is created. To disable it:

void disableDrKonqi()
{
}
Q_CONSTRUCTOR_FUNCTION(disableDrKonqi)
void setDrKonqiEnabled(bool enabled)
Enables or disables launching DrKonqi from the crash handler.
Note
It is the crash handler's responsibility to launch DrKonqi. Therefore, if no crash handler is set, this method also installs the default crash handler to ensure that DrKonqi will be launched.
Since
4.5

◆ setEmergencySaveFunction()

void KCrash::setEmergencySaveFunction ( HandlerType  saveFunction = nullptr)

Installs a function which should try to save the application's data.

Note
It is the crash handler's responsibility to call this function. Therefore, if no crash handler is set, the default crash handler is installed to ensure the save function will be called.
Parameters
saveFunctionthe handler to install

◆ setErrorMessage()

void KCrash::setErrorMessage ( const QString &  message)

Allows providing information to be included in the bug report.

Since
5.69

◆ setFlags()

void KCrash::setFlags ( KCrash::CrashFlags  flags)

Set options to determine how the default crash handler should behave.

Parameters
flagsORed together CrashFlags