Development/Tutorials/Programming Tutorial KDE 4: Difference between revisions

From KDE TechBase
m (Text replace - "</code>" to "</syntaxhighlight>")
 
(37 intermediate revisions by 7 users not shown)
Line 1: Line 1:
This is a tutorial to learn KDE programming by examples. It assumes you are working with KDE 4, not KDE 3.
{{Warning|The tutorial series linked to from this page has been moved to the main page.}}
{{KDE4}}


==Overview==
==Overview==
===Basics===
===Basics===
KDE heavily depends on Qt. Many KDE classes inherit from Qt classes. KDE 4 is based on Qt 4, KDE 3 is based on Qt 3. When this tutorial introduces a new Qt class, you're also learning KDE programming.
KDE heavily depends on Qt. Many KDE classes inherit from Qt classes. KDE 4 is based on Qt 4, KDE 3 is based on Qt 3. When this tutorial introduces a new Qt class, you're also learning KDE programming.
===Getting Help===
 
====Finding documentation====
==Your lessons==
 
=== [[../First program|Hello World]] ===
 
If you read the above, you will be taken into a world where every line of code is friendly and good to beginners.
 
=== [[../Using_KXmlGuiWindow|Using KXmlGuiWindow]] ===
 
This tutorial shows you the magic of an application's most important thing: The main window.
 
=== [[../Using_KActions|Using KActions and XmlGui]] ===
 
Maybe you want to guide your users through your own menues, then this is right for you.
 
=== [[/Using_KConfig|Using KConfig XT to store and retrieve settings]] ===
 
You always wanted to store configuration options ? Then eat this!
 
=== [[/How to write an XML parser|How to write an XML parser]] ===
 
Yes, even XML parsers are explained here.
 
=== [[/Using_QTableWidget|Using QTableWidget]] ===
 
A QTableWidget is an easy way to present an editable table to the user.
 
=== [[/Using_QTreeWidget|Using QTreeWidget]] ===
 
A QTreeWidget is like a QTableWidget with hierarchical display.
 
=== [[/KDirWatch|Using KDirWatch]] ===
 
With KDirWatch, your application gets notified if a given file changes.
 
==Getting Help==
===Finding documentation===
Whenever you have a KDE class and want the API documentation for it (KApplication, for example), point a konqueror window to  
Whenever you have a KDE class and want the API documentation for it (KApplication, for example), point a konqueror window to  


<code>kde: KApplication</code>
<syntaxhighlight lang="text">kde:KApplication</syntaxhighlight>


Be aware that the <tt>kde:</tt> konqueror shortcut only works for classes in kdelibs. If you ask for a class outside of kdelibs or a class that the API search software doesn't know about, you'll be redirected to the main API documentation page. You will need to navigate from there to find the class you're looking for.
Be aware that the <tt>kde:</tt> konqueror shortcut only works for classes in kdelibs. If you ask for a class outside of kdelibs or a class that the API search software doesn't know about, you'll be redirected to the main API documentation page. You will need to navigate from there to find the class you're looking for.
Line 14: Line 50:
If you need to look up the Qt API documentation for a class, you can point a Konqueror window to
If you need to look up the Qt API documentation for a class, you can point a Konqueror window to


<code>qt: QApplication</code>
<syntaxhighlight lang="text">qt:QApplication</syntaxhighlight>


This can be done in addition to browsing the Qt documentation locally, or using Qt Assistant.
This can be done in addition to browsing the Qt documentation locally, or using Qt Assistant.


====Finding other developers====
===Finding other developers===
=====Mailing lists=====
====Mailing lists====
There are two main development mailing lists:
There are two main development mailing lists:
*The [http://mail.kde.org/mailman/listinfo/kde-devel kde-devel mailing list] for general development issues
*The [http://mail.kde.org/mailman/listinfo/kde-devel kde-devel mailing list] for general development issues
Line 26: Line 62:
Many other mailing lists for certain applications also existing. Before posting a question, it's always best to make sure you direct it to the right list. Emailing your question to the right list can help you get an answer faster. You can get an overview of the various available mailing lists at http://www.kde.org/mailinglists
Many other mailing lists for certain applications also existing. Before posting a question, it's always best to make sure you direct it to the right list. Emailing your question to the right list can help you get an answer faster. You can get an overview of the various available mailing lists at http://www.kde.org/mailinglists


=====IRC=====
====IRC====
If you're looking for something a bit more in the instant gratification department, then feel free to ask your question on IRC. KDE uses the [http://www.freenode.org Freenode] network and the easiest way to get on IRC is to point your favorite IRC client to irc.kde.org. There are several IRC clients available for KDE such as konversation and ksirc. There are two main channels for KDE development:
If you're looking for something a bit more in the instant gratification department, then feel free to ask your question on IRC. KDE uses the [http://www.freenode.org Freenode] network and the easiest way to get on IRC is to point your favorite IRC client to irc.kde.org. There are several IRC clients available for KDE such as konversation and ksirc. There are two main channels for KDE development:
*The [irc://irc.kde.org/kde-devel #kde-devel] channel for general KDE development questions
*The [irc://irc.kde.org/kde-devel #kde-devel] channel for general KDE development questions
*The [irc://irc.kde.org/kde4-devel #kde4-devel] channel for questions specific to KDE 4 development
*The [irc://irc.kde.org/kde4-devel #kde4-devel] channel for questions specific to KDE 4 development
Additionally, there are channels for discussing the sub-frameworks of KDE 4:
*The [irc://irc.kde.org/plasma #plasma] channel for development on Plasma. The new KDE 4 desktop framework.
*The [irc://irc.kde.org/solid #solid] channel for development on Solid. The hardware detection/management framework for KDE 4.
*The [irc://irc.kde.org/phonon #phonon] channel for development on Phonon. The new KDE 4 multimedia framework.


As with mailing lists, many applications have their own IRC channel. However, there currently is not a list of common IRC channels available. If you need to ask a question about a specific application, check that application's home page to see if there's an IRC channel available specifically for that application. If a channel is not listed, it's best to ask your question on one of the above two general development discussion channels.
As with mailing lists, many applications have their own IRC channel. However, there currently is not a list of common IRC channels available. If you need to ask a question about a specific application, check that application's home page to see if there's an IRC channel available specifically for that application. If a channel is not listed, it's best to ask your question on one of the above two general development discussion channels.
Line 39: Line 80:
* Don't ask the question more than once. Even though the channel is active, the right person may not be available to provide an answer. If you are told to wait for a certain person to come online, be sure to ask again when you see them come online. Again, if you don't receive a response to your question in about an hour, it's best to send an email.
* Don't ask the question more than once. Even though the channel is active, the right person may not be available to provide an answer. If you are told to wait for a certain person to come online, be sure to ask again when you see them come online. Again, if you don't receive a response to your question in about an hour, it's best to send an email.


==Your lessons==
==Suggested reading==
* [[/First program|Beginner Tutorial 1]] - Hello World
* http://developer.kde.org/~wheeler/cpp-pitfalls.html (C++-specific)
* [[/Using_KMainWindow|Beginner Tutorial 2]] - Using KMainWindow
* http://edu.kde.org/development/tips.php (KDE-specific)
* [[/How to write an XML parser|How to write an XML parser]]
* http://doc.trolltech.com/4.2/examples.html (QT-specific)
* [[/How to load and save configuration|How to load and save configuration]]
* [[/How to use CMake build system|How to use CMake build system]]
* [http://developer.kde.org/documentation/other/makefile_am_howto/en/index.html How to write Makefile.ams]
* [[/Drag-and-drop|Drag-and-drop]]
* [[/command-line-options|Command line options]]
* [http://edu.kde.org/development/tips.php#HowtodealwithsoundwhencodingaKDEapplication How to write sound programs]
* [[/printing|Printing]]
* [[/rc files|RC files]]
* [[/How to write Kontact plugins|How to write Kontact plugins]]
* [[/Exceptions|How to work with Exceptions]]
 
==Suggested readings==
http://edu.kde.org/development/tips.php

Latest revision as of 20:54, 29 June 2011

Warning
The tutorial series linked to from this page has been moved to the main page.
Tip
Note: This page is about KDE 4. It isn't applicable for KDE 3 development.

Overview

Basics

KDE heavily depends on Qt. Many KDE classes inherit from Qt classes. KDE 4 is based on Qt 4, KDE 3 is based on Qt 3. When this tutorial introduces a new Qt class, you're also learning KDE programming.

Your lessons

Hello World

If you read the above, you will be taken into a world where every line of code is friendly and good to beginners.

Using KXmlGuiWindow

This tutorial shows you the magic of an application's most important thing: The main window.

Using KActions and XmlGui

Maybe you want to guide your users through your own menues, then this is right for you.

Using KConfig XT to store and retrieve settings

You always wanted to store configuration options ? Then eat this!

How to write an XML parser

Yes, even XML parsers are explained here.

Using QTableWidget

A QTableWidget is an easy way to present an editable table to the user.

Using QTreeWidget

A QTreeWidget is like a QTableWidget with hierarchical display.

Using KDirWatch

With KDirWatch, your application gets notified if a given file changes.

Getting Help

Finding documentation

Whenever you have a KDE class and want the API documentation for it (KApplication, for example), point a konqueror window to

kde:KApplication

Be aware that the kde: konqueror shortcut only works for classes in kdelibs. If you ask for a class outside of kdelibs or a class that the API search software doesn't know about, you'll be redirected to the main API documentation page. You will need to navigate from there to find the class you're looking for.

If you need to look up the Qt API documentation for a class, you can point a Konqueror window to

qt:QApplication

This can be done in addition to browsing the Qt documentation locally, or using Qt Assistant.

Finding other developers

Mailing lists

There are two main development mailing lists:

Many other mailing lists for certain applications also existing. Before posting a question, it's always best to make sure you direct it to the right list. Emailing your question to the right list can help you get an answer faster. You can get an overview of the various available mailing lists at http://www.kde.org/mailinglists

IRC

If you're looking for something a bit more in the instant gratification department, then feel free to ask your question on IRC. KDE uses the Freenode network and the easiest way to get on IRC is to point your favorite IRC client to irc.kde.org. There are several IRC clients available for KDE such as konversation and ksirc. There are two main channels for KDE development:

  • The #kde-devel channel for general KDE development questions
  • The #kde4-devel channel for questions specific to KDE 4 development

Additionally, there are channels for discussing the sub-frameworks of KDE 4:

  • The #plasma channel for development on Plasma. The new KDE 4 desktop framework.
  • The #solid channel for development on Solid. The hardware detection/management framework for KDE 4.
  • The #phonon channel for development on Phonon. The new KDE 4 multimedia framework.

As with mailing lists, many applications have their own IRC channel. However, there currently is not a list of common IRC channels available. If you need to ask a question about a specific application, check that application's home page to see if there's an IRC channel available specifically for that application. If a channel is not listed, it's best to ask your question on one of the above two general development discussion channels.

In order to get the most out of your IRC experience, it's best to follow these guidelines when asking questions:

  • If you have a question, just ask it. There's no need to ask if you can ask a question.
  • Be prepared to wait for an answer. Even though IRC is more real-time mode of communication, there may not be anyone available to answer your question immediately after you ask it. In general, if you don't receive a response on IRC in about an hour, it's best to send an email.
  • Don't ask the question more than once. Even though the channel is active, the right person may not be available to provide an answer. If you are told to wait for a certain person to come online, be sure to ask again when you see them come online. Again, if you don't receive a response to your question in about an hour, it's best to send an email.

Suggested reading