About this tutorial
This tutorial explains how to use KParts components in a KDE application. It first shows how to create a KParts-enabled main window, then how to define its GUI with XML, and finally how to locate and create the appropriate ReadOnlyPart for a given MIME type. The tutorial then shows how to host multiple parts in the same main window, and how to use a KParts PartManager to handle part activation to update the GUI when switching parts.
KParts is the component technology that has been introduced in KDE 2. KParts allows KDE applications that need the same functionality to share a component for this task, "embedding" the graphical component into the application's window. KParts components are mainly viewers and editors.
The tutorial is divided into three sections that detail the construction of a "universal viewer" capable of displaying any kind of data:
- Creating a KParts-enabled window
- Merging the user interface
- Locating the installed KParts components
The tutorial extends the viewer by showing how to use multiple parts in the same window.
The previous tutorial, "Creating KParts components, Part 1: Build KParts components", shows how to write KDE components and how to make them available to other applications.
Readers should be familiar with C++ application development and with Qt's basic concepts. (See Resources for links to comprehensive references.) Previous experience with KDE development will help in following the tutorial, although it isn't a requirement. Working through the previous KParts tutorial, "Creating KParts components, Part 1: Build KParts components", is also highly recommended as preparation for this tutorial.
To gain an understanding of the KParts component architecture, read the article "Coding with KParts," also by David Faure.
To run the code in this tutorial, you need the following tools:
- KDE 2.x or 3.x and its development packages. KDE 3 is recommended, since it simplifies some of the code needed to use KParts. Download KDE from kde.org.
- A C++ compiler (usually gcc) and other standard GNU programming tools (make, autoconf etc.), which all come with any Linux distribution. You can download gcc from GNU.
- Developers who prefer an IDE instead of a simple text editor can use KDevelop.
- Without
KDevelop, it is necessary to use thekdesdkpackage to generate a compilation framework. You can get kdesdk from kde.org (as well as from many other places Web-wide).
- The tutorial uses the words component and part interchangeably, since a KParts component is called a part.
- The variable $prefix designates the prefix (in other words, base
directory) where KDE is installed. This is
/usron many distributions. The best way to check is to runkde-config --prefix.

