*kDebug() (kdDebug() in KDE3) calls are a simple but efficient way to debug an application.

*kDebug() (kdDebug() in KDE3) calls are a simple but efficient way to debug an application.

Line 38:

Line 38:

*kdbg is a nice graphical frontend to gdb with a KDE GUI. It has support for many Qt types (including QString).

*kdbg is a nice graphical frontend to gdb with a KDE GUI. It has support for many Qt types (including QString).

*Memory leak tracer : See kdesdk/kmtrace. The README explains it all.

*Memory leak tracer : See kdesdk/kmtrace. The README explains it all.

−

*qdbus and dbus-viewer from Qt allow to browse DBus interfaces and to easily make DBus calls.

+

*qdbus and dbusviewer from Qt allow to browse DBus interfaces and to easily make DBus calls.

Check [[Special:myLanguage/Development/Tools|this page]] and kdesdk, there are a bunch of useful scripts there.

Check [[Special:myLanguage/Development/Tools|this page]] and kdesdk, there are a bunch of useful scripts there.

Line 88:

Line 88:

===Is there a preferred way to print debug output on stderr?===

===Is there a preferred way to print debug output on stderr?===

−

Yes, you must use kDebug():

+

Ναι, πρέπει να χρησιμοποιείσεται το KDebug() :

<syntaxhighlight lang="cpp-qt">

<syntaxhighlight lang="cpp-qt">

Line 109:

Line 109:

To make it clear: do NOT use <tt>qDebug()</tt>, this one does not get disabled at releases. Also avoid using <tt>assert()</tt> or <tt>kFatal()</tt> which lead to a crash when something goes wrong and that is not a nice experience for the user. Better detect the error, output a <tt>kWarning()</tt> or <tt>kError()</tt>, and recover if possible.

To make it clear: do NOT use <tt>qDebug()</tt>, this one does not get disabled at releases. Also avoid using <tt>assert()</tt> or <tt>kFatal()</tt> which lead to a crash when something goes wrong and that is not a nice experience for the user. Better detect the error, output a <tt>kWarning()</tt> or <tt>kError()</tt>, and recover if possible.

−

To get timestamps with your debug output, which are useful for debugging multi-threaded, networked and asynchronous operations, <tt>export KDE_DEBUG_TIMESTAMP=1</tt> before running your app. Since KDE SC 4.5.

A core file is an image of the memory when your application crashed. Using the core file, you can know which variables were set and where your application crashed.

Some distributions disable the generation of core files. To re-enable them, use ulimit -c unlimited.

Once you have a core file for a crash, you can examine it with gdb appname core . This will open gdb on the core file for the given application. Once at the gdb prompt, the most useful command is bt which generates a backtrace of the crash.
For more information about how to use gdb, see this page

Then in gdb you can do printqstring myqstring to see its contents.
For instance, QString myqstring = QString::fromLatin1("contents"); can be examined using

(gdb) printqstring myqstring
$1 = "content"

See the kde-devel-gdb file for the other macros it defines.

[edit]I have no symbol when I debug an app that uses kpart, what should I do?

You must stop just after the main to load the debugging symbols of the shared library. After that, you can debug normally.
One can go as far as creating a gdb macro, to stop right after the part was loaded. For kword, by example, I use:

Here are some steps that you can use to troubleshoot why your signal/slot connection is not working (your slot does not get called for some reason).

1) Verify that the connect() doesn't print a warning to the console at runtime.

If it does, check that you wrote Q_OBJECT, that the parameter names are not in the connect, that the parameter types are compatible, and that the slot is defined, and that the moc was compiled.

1b) Or you can just check to see what connect() returns as a bool. Although this won't give you the error message.
2) Verify that the signal is indeed emitted
3) Verify that the receiver isn't already deleted at that time
4) Verify that emitter->signalsBlocked() returns false

The syntax is much like cout, you can use many native types between the "<<". This will print out a debugging message, which will automatically be turned off at release time (by --disable-debug). In case you want the message to still be there during releases, because it's a warning or an error, use kWarning() or kError().

Components and libraries are advised to use a debug area number, as in kDebug(1234). For this, the number must be registered in kdelibs/kdecore/kdebug.areas. Debug areas make it possible to turn off or on the debug output for specific area numbers, using the kdebugdialog program, which is part of kdebase. kdebugdialog --fullmode also permits to control where to log debug output. It is usually not necessary to register area numbers for standalone applications, unless it's so complex that you want to divide the output into several areas.

It is possible to omit the debug area number when calling kDebug by adding the following code to your top-level CMakeLists.txt:

To make it clear: do NOT use qDebug(), this one does not get disabled at releases. Also avoid using assert() or kFatal() which lead to a crash when something goes wrong and that is not a nice experience for the user. Better detect the error, output a kWarning() or kError(), and recover if possible.