Development/FAQs

From KDE TechBase
Revision as of 14:10, 23 December 2006 by Tbscope (talk | contribs) (Adding the developer FAQ page. Basic without layout and improvements)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

General questions

I want to start this new application. What do you advise?

We all agree that there are plenty of KDE applications that need to be written. But there are also a lot of existing kde applications that need your help.

To see the areas where help is needed, check this page.

Before starting a new application, it's always a good idea to check www.kde-apps.org for existing applications and to ask on the [email protected] mailing-list whether someone is already working on a similar project.

I am a developer, how can I contribute to KDE?

Check the open jobs from the job list, there is certainly one that you can take. KOffice and KDevelop, despite being very praised, have very few developers, so you might check there. There is no need to be a KDE core-developer to help. KDE is very modular so you can perfectely improve one area without knowing how the whole system works.

You can also ask on kde-devel if someone needs help on an application. Use the latest version of KDE and spot things that are needed. A theme generator? A konsole schema editor? Improve a game? There is always a small feature missing. Go and implement it!

Are you familiar or attracted with a specific field? See if there is a related application that could use your help. Or write one. KDE needs more non-geek oriented applications.

I am not a developer, how can I help?

There are plenty of tasks that don't require development skills. Write reviews of applications for the promoting of KDE (see the kde-promo mailing-list), help the documentation team (see i18n.kde.org/doc), help the translations (see i18n.kde.org), help to filter the incoming bugs (see bugs.kde.org).

Where can I find images of Konqi the dragon?

The Konqi for some people SDK is at ftp.kde.org/pub/kde/devel/konqi_sdk.tar.bz2
It was posted to artist.kde.org before that site ceased to be updated.

What is the level required to contribute to KDE? What should I learn? What should I read?

You need to know C++. Read the Qt tutorials and browse the Qt docs to get familiar with what's available with Qt. Then read the KDE tutorials and browse architecture and documentation. You can also read the KDE Book, it can not harm. But you don't have to be familiar with the whole KDE architecture to become a kde developer. Using kde's technologies is quite easy, so concentrate on what you really need, you can learn the other bits later on. developer.kde.org and doc.trolltech.com (also in your $QTDIR/doc/html) are invaluable resources, take advantage of them. Then, browse the source, look for the examples directories, see how the other did code their applications. Reading and writing code is the best way to learn.

What is SVN? How do I get KDE from SVN?

See the [anonymous SVN page].

What should I put in my .subversion/config?

[miscellany] global-ignores = *.moc *.moc.cc *.moc.cpp config.log config.status \ config.cache *.gmo .deps .libs SunWS_cache *.lo *.la *.rpo *.la.closure \

  • _la_closure.cpp *_la_closure.cc *_la_closure.cxx *.all_cc.cc *.all_cpp.cpp \
  • .all_C.C *.all_cxx.cxx *_meta_unload.cc *_meta_unload.h *_meta_unload.cpp \
  • _meta_unload.C *_meta_unload.cxx index.cache.bz2 .memdump Makefile.rules.in \

Makefile.calls.in Makefile.rules Makefile.calls autom4te.cache *.kidl \

  • .o *.lo *.la #*# .*.rej *.rej

And to make svn diff ignore whitespace, and print function names: [helpers] diff-cmd = /usr/local/bin/_svndiff

with the following in /usr/local/bin/_svndiff: #!/bin/sh exec /usr/bin/diff -b -u -p "$@"

Don't forget to make /usr/local/bin/_svndiff executable.

I want to put my app in KDE:

There are three requirements:

  • your app must compile with the latest version of KDE (SVN trunk).
  • your app must be stable.
  • your app must be maintained. You will probably get a good deal of bug reports and wishes. People expect you to fix the bugs and implement the wishes that make sense.

See also the next question.

Is it better to develop inside or outside KDE?

As core developer Waldo Bastian explains in a copyrighted mail:


Being part of KDE means that you have to work together with others. Such cooperation brings along advantages but it also brings along responsibilities.
Some of those advantages are: your code ends up on all distro's, people might fix your bugs, you get free translations and documentation, you get tons of bugreports.
On the other side there are disadvantages and responsibilities: you will have to communicate with other developers about your work, other people might make changes to your code, you will have to respect release freezes, you get tons of bugreports and people actually expect that you fix them as well (what are they smoking?), people expect you to maintain your code.
You can't chose for the advantages and ignore the responsibilities that come with it, it's a complete package, it's both or nothing.
In general it should be the author of a piece of software that chooses to put his application in SVN. We usualy don't put software in KDE SVN unless the author wishes to do so. The other way around, if the author prefers to work on his application outside SVN then that's his right as well. Unless there is a split in the actual group of people working on the application it makes no sense to fork the development of an application because of that.
BUT... by putting your code under and open source license and putting it in KDE SVN you give the world at large, as well as KDE in particular, the irrevocable right to use your code. And KDE will use that right at its discretion to protect the interests of KDE, even if that goes against the wishes of the author at that point in time.

It is important to know that but don't be afraid. Usually, things work very well. In 5 years, it has only happened once that a developer had his work put kept in KDE while he wanted to remove it.

How do I get SVN access to kde?

Send a mail to sysadmin (at) kde (dot) org justify why you need SVN access. Make sure to specify your full name and e-mail address, if the From field in your mails doesn't specify them. Please include the name of your bugs.kde.org account, if non-existent please create one so that it can be given usual developer rights. Closing bugs.kde.org reports with keywords in commit comments only works if the email address of your SVN and bugs.kde.org accounts match. You can change your bugs.kde.org address in the Bugzilla user settings. You can currently choose between the standard SVN protocol (https using a password) and the svn+ssh using an ssh key. If you choose https, send also an encrypted password (for instance using useradd dummy ; passwd dummy ; grep dummy /etc/passwd /etc/shadow) and see also the tutorial. If you choose svn+ssh, send a public ssh key instead (e.g. ~/.ssh/id_dsa.pub) See also How do I create a SSH key? If you are contributing to an application that is not yours, it is a good idea to first submitting your coding as patches to the author and let him apply them. If the author is not maintaining his application, you might become the new maintainer... Although there is no restrictions on SVN rights, we expect you not to mess up other developers' code without their consent. You must also respect the feature freezes of the release schedule (published on developer.kde.org) A detailed list of rules you should follow when committing to the KDE SVN repository are listed in the KDE SVN Commit Policy.

My app is not stable but I would like to have it in KDE

As a first step, we can put it in playground (== kde-alpha). Develop it there and when it is ready, ask your app to be moved to the appropriate KDE package or the extragear module.

I don't want to lose my SVN history.

This is no longer possible with Subversion. Maybe in the future, if the server is upgraded and allows that.

What is kdebindings?

It contains Qt/KDE bindings for Java to use Qt/KDE classes with Java, DCOP bindings for C, Java, Perl, Python to use DCOP in those langages and XParts to embed non-KDE apps as a KPart. There are also other bindings for kde which are not maintained by KDE. Check the binding page of developer.kde.org.

Does the feature freeze apply to kdenonbeta/playground?

No, kdenonbeta and playground are not a released packages. The same is true for kdereview and extragear: they are not frozen and released. But if you want your app to move to a package, ask for it before the beta-release.

Can I have a stable and an unstable KDE on the same computer?

Yes, check the Building 2 Versions documentation.

How do I know which version of Qt/KDE I am using?

Launch the KDE Control Center. The splash screen includes Kde version information.

kde-config and all kde programs accept --version as argument.

Qt-copy or Qt from trolltech.com : if one were doing a clean build of trunk, which would be preferable?

You can use either. They are binary compatible (forward and backward). There can be, however, a few bugfixes in qt-copy over the most recent Qt release. In special, if building qt-copy, pay attention to the apply-patches script.

How can I checkout a single directory from a SVN module?

Checkout the top-level dir with 'svn co -N /modulename', 'cd modulename', 'svn up admin' to get the admin/ dir and then finally checkout the dir you want with 'svn up subdir' For instance, to get only reaktivate from kdenonbeta: svn co -N /kdenonbeta; svn up admin; svn up reaktivate

Then compile as usual. 

The same answer applies to the question "How do I get a single language out of kde-i18n?". If you don't know the name of the directory you want to check out, you can browse websvn.kde.org to find it.

How can I get one of the KDE application as a standalone tarball?

kdesdk/scripts/svn2dist is a script to extract an application from the KDE source tree and package it as a standalone application.

How do I close my own bug reports?

If you reported a bug that is fixed in a new release of KDE but is still reported as open, you can close it. It might happens because your bug is the same as another one, or simply because the developer fixed something without noticing that it would correct your bug. You can do that from your Subversion commit. To do so, append to your commit message a line like this: BUG: XXXXX Where XXXXX is the bug report you want to close. If the report you're closing is adding a new feature, you can use FEATURE instead of BUG. Managing a bug list is a huge task for the developers and they usually have a lot of bugs listed, some being fixed already without their knowledge, some being unreproducable, some without enough information to be corrected, etc. If you can help managing and updating the list of outstanding bug, you will be gladly welcome. And you will receive an even happier welcome if you provide a patch.

How do I create a SSH key?

SSH makes use of two keys: a private key and a public key. You should keep the private key secret at all times and only place it on machines over which you have direct control. Public, shared, and community machines are not suitable environments to store SSH private keys. Take action to help prevent theft of your SSH private key data. Setting a password on your SSH private key will help reduce the risks involved with private key theft. Generate a key pair for each major location you work from. This helps to reduce the impact when your key gets stolen. When someone obtains access to your private key, your key can be abused in attempts to compromise KDE servers. Well known open source projects have been compromised this way in the past, YOU must help us to make sure that this doesn't happen with KDE servers as well. For that reason it is important to notify sysadmin (at) kde (dot) org immediately when you notice that someone may have had access to your private key for example when a computer on which it was stored has been hacked or infected with a virus, worm or trojan.

If you choose to make a backup of your SSH private key data, please ensure that any such backup is stored in a secure manner as well. 
For the practical part, the following command can be used to generate a SSH private/public key pair with ssh-keygen -t dsa . This will create a private key as ~/.ssh/id_dsa and
a public key as ~/.ssh/id_dsa.pub. 
There are times when you may want to use a key of a different name to the default, perhaps to use seperate keys for different projects. To let SSH know which key you want to use for KDE.org, you can keep a list of servers and their corresponding keys in ~/.ssh/config. For example, 
Host svn.kde.org 

IdentityFile ~/.ssh.id_dsa_kde

In order to use SSH to access KDE servers you need to send your public key to sysadmin (at) kde (dot) org. 

How can I monitor changes made by others?

The kde-commits mailinglist carries automatic notifications for all changes made in the KDE SVN repository. The KDE-Commits mailinglist is very high traffic. An alternative is CommitFilter which allows you to get notification for only those areas that interest you.


Technical questions

How do I start a new application?

The easiest way is to use kdesdk/kapptemplate or kdevelop to generate the Makefile.am . Or you can just copy a Makefile.am from another app and install it in a new toplevel directory of existing KDE sources. Or you can start the old way, from scratch, but you'll miss the power of the autoconf/automake framework.

What is dcop, kpart, kio, kdesktop, kdeinit, ...

Check developer.kde.org, especially the architecture documents. Check also the kde book.

Do I really need to use dcop and kpart?

Well, you are not forced to but it is a _lot_ better. KPart allows powerful code reuse. Dcop allow scriptability and is very powerful. Given how simple it is to use these technology and how widely they are deployed, it is a shame not to use them if you can.

How do I write a Makefile.am?

The guide on how to write Makefile.ams is now a separate document, makefile_am_howto.

How does the Makefile generation works?

It uses autoconf and automake with another layer by the means of a program named am_edit. But don't try to understand how to use all that. It is quite complex and the strength of KDE is that you don't actually need to understand that stuff, a core-developer already did that for you. Basically, automake transforms the Makefile.am into a Makefile.in, then am_edit runs and replaces in the Makefile.in all the KDE-specific tags with their real meaning, and configure will create a Makefile out of the Makefile.in

Why does KDE produce .lo and .la files? Why are the files hidden in a .libs directory? Why is my executable a shellscript?

Because KDE is using the GNU tool called "libtool". So the question forks into two: "Why use libtool?" and "Why does libtool create .lo and .la files, and shellscripts?". KDE uses libtool for portability reasons. libtool takes care of the differences between the compilers and especially linkers on various platforms, so that we don't have to bother with that, even when writing shared libraries. The .lo and .la files are used by libtool to add some information (read them, they are plain text), about object files and libraries. For instance, it remembers which libraries a given library depends upon. Without it, we'd still have to write link lines such as -lkparts -lkio -lkdeui -lkdecore -lqt -lXext -lX11 etc. etc. So you may find it a bit strange that things are "hidden" in .libs, but the gain is huge: complete portability, at no cost for the developers.

What targets are available to make?

  • all: the default target (the one you get when typing "make").
  • clean: removes all the generated files
  • distclean: also removes the files generated by Makefile.cvs Not very useful within KDE (see dist for the "dist" concept and svn-clean for a better way to make really clean).
  • dist: supposedly for making a tarball out of SVN sources, but not very well supported within KDE. Better use kdesdk/scripts/cvs2pack for that.
  • force-reedit: re-run automake and am_edit on the Makefile.am
  • install: well, install everything :)
  • install-strip: install everything and strips binaries (removes debugging symbols).
  • install-exec: only install the binaries and libraries
  • install-data: only install the data files
  • check: compiles the test programs (i.e. those defined with check_PROGRAMS). It is even possible to actually run some tests during "make check", see kdelibs/arts/tests/Makefile.am

I have a checkout of SVN, there is no configure and no Makefile?

Use make -f Makefile.cvs It will run all the Makefile generation steps

How can I temporarily exclude certain directories from build?

While hacking a program it might be useful to exclude certain directories from build that would otherwise be recompiled, but don't actually need to be. Also, if you checked out source code that didn't compile and you don't have the time or knowledge to fix the error you might want to turn off compilation of the directory alltogether. There are two cases. Toplevel directories, and subdirectories. For toplevel directories you can simply erase them (or not check them out).

If for some reason you don't want to do that, you can also set DO_NOT_COMPILE="someapp" before calling configure, this will make configure skip "someapp". To only compile very few toplevel dirs, instead of using DO_NOT_COMPILE to exclude most of them, you can list in a file named 'inst-apps', at the toplevel, the toplevel subdirs you want to compile. 

To turn off compilation of any directory, including subdirectories, you have to modify the Makefile or Makefile.am files. Makefile.am is not recommended because that file is in KDE SVN and you could accidentally commit your changes. So we'll modify the Makefile instead here:

Open the Makefile in the directory immediately above the directory you want to exclude in a text editor and look for a variable SUBDIRS. It will often look somewhat like

SUBDIRS = share core ui . proxy taskmanager taskbar applets extensions data Just remove the directory that you want to exclude and save your file. A new make will skip the directory you just removed.

Sometimes you'll have to look harder because the SUBDIRS variable consists of a number of other variables:

SUBDIRS = $(COMPILE_FIRST) $(TOPSUBDIRS) $(COMPILE_LAST) Here you have to find the COMPILE_FIRST, TOPSUBDIRS and COMPILE_LAST variables. One of those contains the dir you want to exclude. Remove the directory where you find it and save the Makefile again. To undo your changes you can either regenerate the Makefile from scratch or revert to an older backup (you did make one, did you? :-).

To regenerate a Makefile, just make force-reedit.
You can also copy the original line in the file when editing and make it a comment by prefixing a '#' in front of it. Then undoing the change is as easy as making the modified line a comment and removing the comment in the original line.

What are the various compilation options?

--enable-debug :

Add debug symbols, disable optimisations and turns logging of kdDebug() on. 

--disable-debug:

The opposite of the previous one: enable optimisations and turns kdDebug() logging off. 

--enable-final:

Concatenates all .cpp files into one big .all_cpp.cpp file, and compiles it in one go, instead of compiling each .cpp file on its own. This makes the whole compilation much faster, and often leads to better optimised code, but it also requires much more memory. And it often results in compilation errors when headers included by different source files clash one with the other, or when using c static functions with the same name in different source files. 

This is a good thing to do at packaging time, but of course not for developers, since a change in one file means recompiling everything. --disable-fast-perl

By default KDE uses perl instead of sh and sed to convert Makefile.in into Makefile. This is an addition to autoconf done by Michael Matz. You can use this option to disable this but it is a lot slower. 

Which compile option do you recommend?

If you are a developer, you should definitely compile Qt and KDE with --enable-debug. You will then be able to debug your program even inside Qt and KDE function calls. If you are just a user, you can still use --enable-debug. KDE will occupy more space on your hard disk but it won't slow down your desktop. The advantage is that you get stack trace when an application crash. If you can reproduce a crashing behaviour, go to bugs.kde.org, check that your bug doesn't exist yet and submit it. It will help us improve kde. For Qt, the compilation options are explained in qt-copy/README.qt-copy.

Tips to increase compilation speed?

See --enable-final above :) . "make final" uses the all-in-one-file trick in the current directory even if --enable-final wasn't used, and "make no-final" does a normal compilation in the current directory even if --enable-final was used. Include your moc files! Header files declaring a QObject descendant have to be run through moc to produce a .moc file. This .moc file has to be compiled, for which two possibilities exists: compile it separately, or #include it in the C++ file implementing that above mentioned class. The latter is more efficient in term of compilation speed. BTW, kdesdk/scripts/includemocs does this automatically. Buy more ram, a faster machine and another processor. On a bi-PIII 866 MHz with 1GB of RAM, kde compiles at a decent speed :-)))

There is a STRIP variable set in the Makefile but it doesn't seem to be used?

The strip is done at install. To use it, use "make install-strip" instead of "make install".

What indentation should I use?

If you are working on an existing application, respect the author's indentation. Else, you can use whatever indentation you like.

What is the difference between i18n and I18N_NOOP?

If you do

QString translatedStuff = i18n("foobar");
 translatedStuff will contain the translation of "foobar", while for
const char *markedStuff = I18N_NOOP("foobar");
 markedStuff will still contain literal "foobar", but translators will know you want "foobar" translated so you can later on do QString translatedStuff = i18n(markedStuff); and get the translation of "foobar", which wouldn't work without that I18N_NOOP. 

So, normally you want to just use i18n(), but in cases where you absolutely need to pass something untranslated, but still need to translate it later or in the case that you have something to be translated before the KInstance exists, use I18N_NOOP.

What is this bug thing with QSpinNumber?

There is a bug in QSpinNumber, that is not corrected yet. Use KSpinNumber instead, it has almost the same features.

I get "virtual tables error"?

This often comes from the moc files not being in sync with the sources, or not linked at all. Check that you are running the right moc. 'which moc' will tell it. Regenerate your moc files (make force-reedit; make clean; make).

Trying to use dcop, I just added k_dcop to myClassHeader.h file but nothing specific seems to happen?

Add myClassHeader.kidl to your Makefile.am and run make again.

Some Makefile.am have a .stub file, what is it for?

Stubs are not very documented. A stub allow you to view a dcop registered application as an object whose methods are its dcop slots. Usually, applications have an appnameIface.h file that contains all the dcop slots. Add a appnameIface.stub in your Makefile.am and use the object appnameIface. See for example kdebase/khelpcenter that uses a konqueror stub.

I have added Q_OBJECT to myClassHeader.h but no moc files is generated?

You need am_edit to reparse your Makefile.am to generate the correct Makefile. If it's the first Q_OBJECT you're using in this directory, you'll need to re-run Makefile.cvs or create_makefile from kdesdk/scripts. Otherwise, you can simply run "make force-reedit". 

To go quicker, I have coded my whole class in a cpp file, how do I get the moc and kidl files generated?

Hmm, don't do that, if some of the classes use the Q_OBJECT macro. The KDE framework (am_edit) doesn't support this very well. Maybe METASOURCES=file.cpp might work for moc files though.

I have developed a kpart (or a plugin). I don't want to install it yet because it is not finished but I need that KDE finds it when I request it using KTrader or KLibLoader. How do I do that?

KDE searches its libraries in $KDEDIR/lib and in the lib directory of all the components of $KDEDIRS (note the additional 'S', this different from $KDEDIR). So, while you are still developing your library and don't want to install it, you can use this trick: cd to your development directory, the one where your library is built. Set up KDEDIRS so that it include your development directory: export KDEDIRS=`pwd`:$KDEDIR Create a pseudo lib directory where KDE should find your component: ln -s .libs lib (all the objects and libraries are built in the .libs directory). Run kbuildsycoca to inform KDE that it KDEDIRS has changed.

Now, KDE should find your library when using KTrader or KLibLoader. 

How can I install additional KDE stuff when I am not root?

If want to install your application privately, configure it with another prefix: for $HOME/kdeprefix, use configure --prefix=$HOME/kdeprefix. Then let KDE know about this prefix: set KDEDIRS to $HOME/kdeprefix:$KDEDIR. To make KDE aware of new prefixes, one can also edit /etc/kderc and add 

[Directories] prefixes=/the/new/prefix

but this doesn't answer this specific question ;-)

Make sure to run "kbuildsycoca" after setting the new KDEDIRS.

My kpart lib is not listed when I request it with KTrader

The mimetype database must be rebuilt when you install new services (such as applications or parts). In theory this happens by itself (kded is watching those directories), but in doubt, run "kbuildsycoca". The best way to debug trader-related problems is to use ktradertest: cd kdelibs/kio/tests; make ktradertest, then run ./ktradertest to see how to use it.

I changed something in kdelibs, installed the new lib, but new KDE apps don't seem to use it?

The solution is simple: start new apps from a command line, then they will use the new lib.

The reason is that applications started by other KDE applications (kicker, minicli, konqueror, etc.) are started via kdeinit, which loads the libs when KDE starts. So the "old" version of the libs keep being used. But if you want kdeinit to start using the new libs, simply restart it. This is done by typing kdeinit in a terminal. 
This is necessary if you can't start things from the command line - e.g. for a kioslave. If you change something in kio, you need to restart kdeinit and kill the running kioslave, so that a new one is started. 

I'm developing both a KPart and a standalone application, how do I avoid duplicated code?

Apps are often tempted to link to their part because they of course have much functionality in common. However this is wrong for the reasons below. A lib is something you link to, a module is something you dlopen. You can't dlopen a lib ; you can't link to a module. A lib has a version number and is installed in $libdir (e.g. $KDEDIR/lib) a module doesn't have a version number (in its name), it's more like a binary (we don't have konqueror-1.14.23 either :), and is installed into kde_moduledir (e.g. $KDEDIR/lib/kde3) (which means it's not in the search path for ld.so, so this breaks on systems without -rpath). If you didn't understand the above, don't worry. The point is: you should NOT make your application link to your (or any other) KPart, nor any other kind of dlopened module. The solutions let the app dlopen the part. This is what KOffice does. However this limits the app to the very limited ReadOnlyPart/ReadWritePart API. Keep in mind that you can't call a non-virtual method whose implementation you don't link to. The solution is to define a ReadWritePart-derived class (like we have in koffice: KoDocument), with new virtual methods. Either this derived class has code (and you need a lib shared by the app and the part, see point 2 below), or an abstract interface (header file only) is enough. You can also use known interfaces to child objects of the part instead of changing the base class of the part itself - this is the solution used by e.g. KParts::BrowserExtension. define a common library with the common classes and let both the part and the app use it. That library can be noinst_ or lib_, both work. In the first case the compiled object code is duplicated, in the second case a real versioned lib will be installed. The idea here is that the part itself is not available to the app, but instead the part is a very thin wrapper around the same classes as the app uses. Only KParts-specific stuff remains in the part.

What is the best way to launch another app?

There is a good answer in the kde2 porting instructions. Check kdelibs/KDE2PORTING.html, also  there. 

How do I create and submit a patch to KDE?

You have spotted a bug and you want to write the code to fix it. Or you want to code a specific feature. Sending a patch is very appreciated by developers. A tutorial is available but here is a description of how you should proceed: 

Get the latest KDE using SVN to check that the code you want to write has not been added yet. Check the bug database to see if your bug is not worked on. Get in contact with the author. His/her name is in the about box or in the source header. If the project has a mailing-list, browse the archives to see if your bug/feature has not been the subject of any discussion. If you can't find any mailing lists or author, simply write to kde-devel. Post a message explaining your intentions. It is important to inform the author(s) about what you are planning because somebody might already be working on your feature, or a better design could be proposed by the author, or he could give you some good advice. Next step is to code your feature. It is usually a good idea to keep an original at hand and to work on a copy. This allow to check the behaviours of both versions of the code. Respect the author's indentation and naming scheme, code carefully, think about side-effects and test everything many times. Using the latest KDE code, make a diff using either svn diff or a diff -uNp original-dir new-dir. Don't send reversed patch. The first argument of diff should be the old directory and the second the new directory. Send a mail to the author/mailing-list with your patch as attachment (don't forget to attach it :-) ). People usually have some remarks on your work and you must work further on your patch to improve it. It is common to see three or four submission before acceptation.

Ok, you have done it, your code has been included in KDE. You are now fully part of the KDE project. Thanx a lot. 

How do I make my application Xinerama and multi-head safe?

Never make assumptions about the geometry of the "desktop" or the arrangement of the screens. Make use of the following functions from kglobalsettings.h: 
static QRect KGlobalSettings::splashScreenDesktopGeometry(); 
static QRect KGlobalSettings::desktopGeometry(const QPoint& point); 
static QRect KGlobalSettings::desktopGeometry(QWidget *w); 
Use splashScreenDesktopGeometry() to determine the geometry of the desktop when you want to display an application splash screen. Use desktopGeometry() to determine the geometry of the desktop with respect to a given point on the desktop, or with respect to a given widget. Do not use the Qt class QDesktopWidget to determine these values yourself. The KDE functions take the user's settings into account, something the Qt functions cannot do. 
It is ideal to try to avoid using the desktop geometry altogether. Your application will be much more standards compliant if you let the window manager place your windows for you. When this is not possible, you have the aforementioned functions available. Please beware that the geometry that is returned from these functions may not start at (0,0)! Do your math correctly! 
One other caution: Both KWin and the NETWM specification have severe difficulties handling struts with Xinerama or "merged" displays. This can result in dead areas on the screen, for instance if kicker does not span a whole edge. There is not much that can be done about this, and you should try to avoid hacks to circumvent this at this time. We hope to find a proper solution for this soon. 

I get an error about KDE not finding UIC plugins, but I know they're installed. What's wrong?

This is almost certainly an installation problem, not a KDE code problem. A number of problems can lead to this, but most likely you have more than one version of Qt laying around and the configure script is calling a different one than KDE is using. 

Another thing that may help is to rebuild and reinstall your kdewidgets.so file, which is located in the kdelibs/kdewidgets directory. Note that if you *do* have multiple versions of Qt, this may compile against the wrong one. This problem creeps up on various mailing lists occassionally, so looking at the archives on lists.kde.org may be helpful.

I put some functions in anonymous namespace and someone reverted it and made those functions static, why?

Symbols defined in a C++ anonymous namespace do NOT have internal linkage. Anonymous namespaces only give an unique name for that translation unit and that is it; they don't change the linkage of the symbol at all. Linkage isn't changed on those because the second phase of two-phase name lookup ignores functions with internal linkages. Also, entities with internal linkage cannot be used as template arguments. 

Can I delete a NULL pointer?

Yes. Calling delete on a null pointer is a noop in C++. Having "if (ptr) delete ptr;" is redundant. Doing "ptr = 0;" after a delete is a good idea, especially if the delete can be called on it from a different code path. 

Debugging

How do I avoid Dr Konqi?

You must set the environment variable KDE_DEBUG (to 1 or whatever you want in fact). 

What is a core file? How do I get a core file?

A core file is an image of the memory when your application crashed. Using the core file, you can now 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.

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

Yes, you must use kdDebug():
#include <kdebug.h>

kdDebug() << "KMyApp just started" << endl; 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 kdWarning() or kdError(). Components and libraries are advised to use a debug area number, as in kdDebug(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. To make it clear: do NOT use qDebug(), this one doesn't get disabled at releases. Also avoid using assert() or kdFatal() which lead to a crash when something goes wrong, never nice for the user. Better detect the error, output a kdWarning or kdError, and recover if possible.

What tools are available to debug my application?

kdDebug() calls are a simple but efficient way to debug an application. gdb, the GNU debugger, is the quickest way to execute step-by-step and investigate variables (prefer the 5.0 version, it is really better than the 4.1.x). Valgrind 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. kdcop and dcop allow to browse the dcop interface and to easily make dcop calls.

Check this page and kdesdk, there are a bunch of useful scripts there. 

How do I print a QString in gdb?

Check out kdesdk, and add this line to your ~/.gdbinit :
source /path/to/kde/sources/kdesdk/scripts/kde-devel-gdb 

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.

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 :

define startkword
break main
run
break 'KoDocument::KoDocument(int, QWidget *, char const *, QObject *, char const *, bool)' cont

How do I debug an ioslave?

See kdebase/kioslave/DEBUG.howto 

Original question list by Philippe Fremy, answers by David Faure.

Contributions from: Marco Krohn, Malte Starostik, Andreas Pour, Waldo Bastian, Lars Knoll, Triskelios, Eric Sigra, Rolf Dubitzky, Martijn Klingens, Karl-Heinz Zimmer, George Staikos.

Please send additional questions, responses or comments to pfremy at kde dot org