Kode KDE Kindly, Kan You?

With a little programming experience, you'll have everything you need to build applications for the Linux desktop when you're done reading this.
Kode KDE Kindly, Kan You?

With a little programming experience, you'll have everything you need to build applications for the Linux desktop when you're done reading this.

by Jason Mott

There are many toolkits to choose from for building Linux desktop applications. Some say this is Linux's downfall; others say it is its greatest feature. I'll stand somewhere in the middle and say choice is good if you choose what meets your needs. Most graphical user interfaces (GUIs) on Linux are based on X, a client/server architecture that allows for networked computers to share GUI applications. With X, the application is the client that sends its graphical output to an X server. The X server accepts applications' output on behalf of its local hardware (or sometimes virtual hardware, but I won't go there in this article). In most cases, the X server and the X client are on the same machine, but use the client/server architecture nonetheless.

The base-level toolkit for building an X client is called Xlib. Xlib is much too low-level and difficult to use by itself to build an application from scratch. As a result, many toolkits have been built on top of Xlib to make it easier to write GUI applications for X. Subsequently, when writing GUI applications using one of the high-level toolkits, you never even know it's a networked application (that it's sending its graphical output to a server).

The two most popular open-source toolkits that layer on top of Xlib are Qt and GTK+, upon which KDE and GNOME are respectively built. Motif is another popular toolkit (not open source, but there is an open-source clone called Lesstif). Figure 1 shows a diagram of these (and more) and their relationship with one another. The farther down on the diagram, the lower the level of API it is. I prefer KDE/Qt for many reasons, but mostly because it's focused on a good user interface and a clean and well-designed API.

Figure 1. Relationships between KDE and GNOME and Various Toolkits

Requirements

I actually built an application from scratch for this article (a calculator) to show how quick and easy it can be. To follow along you'll need some tools—most importantly, KDevelop. I used version 2.0.2 running on KDE 2.2.2. When using KDevelop's setup wizard you'll be told what dependencies you're missing. Visit the KDevelop web site (www.kdevelop.org) or check with your distribution's included software, and get KDevelop installed. If you have KDE as part of your distribution, then you'll have KDevelop.

KDevelop

Most tutorials on application development try to be IDE-agnostic. I've decided against this for a few reasons: KDevelop is free and comes with KDE; KDevelop makes an already easy API even easier, and KDevelop's wizards help the developer conform to KDE user-interface standards. For those who don't like to deal with Makefiles or creating configure files (or even dealing with the easier automake and autoconf), KDevelop will handle these things for you. And for geeks who do like to mess around with Makefiles, KDevelop allows you to tweak them. In fact, your KDevelop application is ready to be built with the traditional ./configure, make, make install. In other words, you're free to break free from KDevelop anytime you want.

The first time you fire up KDevelop it will run you through a setup wizard. The most important piece of the wizard is when it checks for dependencies (Figure 2). Take the time to look through this output; if there are failures listed, do yourself a favor and try to find the libraries needed. The easiest way to do this is to use www.rpmfind.com (if your distribution is RPM-based). For each library that failed, do a search for it on the rpmfind web site. From the search results, select the RPM appropriate for your distribution and install it. Once you've done that, rerun the KDevelop wizard (type kdevelop --setup on the command line or find an entry in your K menu that says KDevelop Setup). If there are still missing items, repeat as necessary.

Figure 2. KDevelop Setup Wizard

Kalculate

The calculator I built is simple and only does basic arithmetic. The whole thing took about two hours to complete (okay, three hours, but I wasn't in a hurry). I was going to name it Kalculator, but there is an obscure application out there that already uses that name. So I chose Kalculate. I did not use nor view any code from KDE's stock calculator called KCalc, which has more mathematical features than mine. I've always felt KDE should have a basic calculator anyway, so I'd like to see user-friendly features added to Kalculate rather than more mathematical features. Therefore, when you're done reading this you can be a part of a living experiment in open-source development—come join the team and add a feature! You'll get special preference if you say this article sent you (sourceforge.net/projects/kalculate).

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Kode KDE Kindly, Kan You?

synthetoonz's picture

I would have liked to see a more entry level explanation of everything. Why are things (functions/objects/classes) arranged the way they are? A line by line breakdown of the code would be excellent.

I'm not exactly entry level. I was writing Motif and X11 code 12 years ago in the Air Force. But, things must have changed a lot in the years since I've worked on *ix guis, because much of the code I see in various KDE/GTk applications seems like nonsense.

I've been sifting through all the "tutorials" I can find on the web about beginning KDE development and have not had much luck getting most of them to even compile (Suse 8.1 pro/KDE 3). (BTW, this calculator app is one of the few that actually do compile on my system.)

I was following one step-by-step tutorial I found online and it began to fall apart after the work they outlined in QT designer was finished. The source code lines they said had to be manually edited didn't exactly look the same as their example, and once edited the project wouldn't build. Grrr. There is some unknown voodoo going on.

I have done work in MFC for Windows (Bleh) and at least there in Visual studio you can get a brainless GUI dialog/window to appear without editing any code. I think part of the problem with the KDE/KDevelop/QT design tools is that things are too loosely linked. They function almost as if they are totally unaware of each other. Having to edit/change certain generic class names used as boilerplate or placeholders in a source file should be done by the tools, not the programmer -- isn't that's what the tools are for.

I think a series of articles explaining KDE/GT development in a step-by-step, line-by-line exposition would a right nifty idea in LinuxJournal. (Perhaps a regular column dedicated to beginner level development.)

Re: Kode KDE Kindly, Kan You?

synthetoonz's picture

Oops.

:%s/GT/Qt/g

heh heh.

Re: Kode KDE Kindly, Kan You?

stampa's picture

Jason, many thanks for your easy to understand article. I am new to Linux and it has inspired me to try to develop a simple Linux app. Previously I was a little confused by KDE/Qt etc but I now want to give it a go. If successful I may be intersested in doing something useful for Sourceforge one day..

I'm disappointed by some of the negative comments people seem to enjoy writing here - I think they should probably get out more and communicate other than by computer once in a while? Thanks again.

Re: Kode KDE Kindly, Kan You?

jmott's picture

Thanks for your kind words. I wish you luck in your KDE/QT adventures.

Don't worry about those that make negative comments. They are clearly not very intelligent, and have some serious emotional issues to work out.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

Good article. Simple is exactly what new Qt developers need to get started. I am coming from an MFC/Windows environment and this is the kind of straightforward article i need to get aquainted with cvs, Qt, and the general development process on Linux.

Muchas Grassy-ass

Re: Kode KDE Kindly, Kan You?

jmott's picture

Glad you liked it!

Re: Kode KDE Kindly, Kan You? Trouble with KDE3 on SuSE 8

Anonymous's picture

I can't get this to work at all on SuSE 8. ;o)

I guess kde 2.2.2 must have some Q?Something that KDE 3 don't got.

Re: Kode KDE Kindly, Kan You? Trouble with KDE3 on SuSE 8

jmott's picture

Kalculate requires KDE 2.2.2, and Suse 8.0 comes with KDE 3.0. KDE 3 changes enough that it isn't compatable with KDE 2.2.2 apps.

Sorry. When the article gets old enough, I'll port Kalculate to KDE 3.0. But since the article states it's a KDE 2.2.2 app I need to wait.

Re: Kode KDE Kindly, Kan You? Trouble with KDE3 on SuSE 8

Anonymous's picture

Rodger that. I knew I wasn't crazy. So I picked up a nice little book on TCL/TK for now. That ought to keep me busy ;o)

Thanks for the response.

Re: Kode KDE Kindly, Kan You? Trouble with KDE3 on SuSE 8

Anonymous's picture

You need to be superuser. So type "su"

and follow with root password.

A great framework article

Romulus007's picture

Jason,

Great job!! Some people are simply un-appreciative of the time (FREE) that others put in to make this community what it is today.

I have not started any Linux development yet, but I will soon. Also, I'm a big Delphi (Object Pascal) fan, but this KDevelop stuff is truly impressive.

Finally, I have to give a big thanks to the KDE folks! They just seem to have an aura of "extreme kwality" about them, whether it's their apps (like KOffice) or their desktop environment.

It's sure good to know that the open source world has them along with the other members of GNOME, Apache, Linux, JBoss, XFree86, MySQL, PostGre, NetBeans, the BSDs (Net, Free, Open), GNU, Eclispe et al (I'm sure I've forgotten other notables!).

History, one day, will rightfully give all of the above mentioned organizations a big THANK YOU for allowing the masses to regain their diginity from proprietary apps or companies that only care about satisfying sahreholders to the detriment of society.

In other words, I am eternally gratefull for all of the wonderful contributions made by everyone in the open source community. It, truly, has inspired me in numerous ways!

L8tr dudes!!

Re: A great framework article

jmott's picture

Thank you so much for your kind words. It's nice to get a complement in an environment where people are all too quick to throw insults.

--Jason

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

using a doc/view for this application is a huge design mistake! That might have "undefined" consequences on newbie developer who are reading this article.

Very poor practive indeed from an article which aims at teaching.

Re: Kode KDE Kindly, Kan You?

jmott's picture

I think it's a very good design, and so do the developers of KDevelop, as it's the default template. I also believe in teaching the real world. I don't insult learners by dumbing down material.

However, I have an open mind. I'd love to hear more details about your opinion.

--Jason

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

Perhaps you're not familiar with KDevelop, but the KDE project template creates app, doc and view source files. It wouldn't make much sense to tell a beginner to ignore the project template, and hand code something.

If the project only took two hours to create, I fail to see any huge design mistake.

-- Richard Dale

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

please correct the first cvs-statement (cvs -d:pserver:anonymouscvs.kalculate.sourceforge.net) into

(cvs -d:pserver:anonymous@cvs.kalculate.sourceforge.net)

the @ is missing.

-gunnar

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

Help
italica

Re: Missing @

scott's picture

Thanks.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

Interesting to see an article posted in the future coming back to haunt us:
"Issue 98: Kode KDE Kindly, Kan You?
Posted on Saturday, June 01, 2002 by Jason Mott"

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

No surprise. When I set timezone in my KDE to UTC, I kan see UTC. If I set timezone for Prague (today UTC+2), I will see just the opposite time: UTC-2, i.e. at 8:00 my KDE panel clock applet insists it is only 4:00.

So if the author acutally wrote the article on May 1 and posted May 15, KDE consistently with its clock logic translated the real creation date (today-15) to KDE date (today+15).

Actually it does not work precisely that, but there might a some time shift involved, too.

73,

OK1FOU

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

Window managers are just clients. They can (and are) written using toolkits. So, the diagram is a bit skewed, window managers should be placed on the client side of TCP/IP, above Xlib certainly, most appropriately at the level of GNOME or KDE. The Motif window manager

In olden days (I've been working with X for about 12 years now), X terminals often had embedded window managers. In one implementation I worked on (an X terminal for NEC in Japan), we also hosted the client libraries (Motif, etc.) on the X server, and the window manager (mwm) was calling Motif directly. In other cases, custom window managers were written that made calls directly into X server routines, bypassing Xlib entirely. In both these cases, placing the window on the side of the X server would be correct. But these are exceptions to the general rule; window managers are clients.

Re: Kode KDE Kindly, Kan You?

jmott's picture

Window Managers were really out of scope for this article, so I tucked it down at the bottom. Sorry for any confusion that may have caused, but applications are really the focus here, not Window Managers.

Thanks for the feedback.

--Jason

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

It's a common misconception to think of KDE as a window manager. Although KDE comes with a window manager, it's certainly not limited to that.

Basically KDE is three things:

* An application development framework. (High Level API)

* The actual Desktop (window manager, panel, desktop with icons, control center, file manager)

* A large number of consistent and easy to use applications.

This article focuses on the first aspect and as such has little to do with window managers.

Cheers,

Waldo Bastian

bastian@kde.org

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

It must be late because it is only now that I notice the "Window Manager" in Figure 1.

Yes, the poster is absolutely right. kwin, the KDE window manager, sits on top of the KDE API on the client side.

Cheers,

Waldo Bastian

bastian@kde.org

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

I think he really meant www.kdevelop.org, not .com...

I don't "kare" enough to waste my time on KDE "krap", but you've got to wonder if the rest of the article is so full with little errors like this.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

Why is KDE programming "krap"?

Get a life and don't slag off people who put a lot

of effort into articles such as this.

Nick

Re: kdevelop.org

scott's picture

Thanks, I'll have that fixed.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

I just dont see why this dummy chooses to encourage the dumb naming tendencies that KDE and GNOME both have. Kuz I KThink KThe KNaming KIs KStupid. GDoesn't GMatter GWhich GDesktop. Retards. Get some focking creativity.

Re: Kode KDE Kindly, Kan You?

jmott's picture

Dummy? I wrote an intelligent, well written article that the The Linux Journal felt fit to not only print in its magazine, but to pay me for. I'm not sure I'm the dummy here. However, if you must know why I encourage the use of the K naming convention I will tell you. It's because there is so much choice on the Linux desktop. The naming convention instantly tells you what the application is written for. So, if you don't like KDE, now you know what applications to avoid.

If you really want to critique articles, I recommend you come up with some more intelligent reviews rather then throwing around 5 year old level insults at someone whom you've never meet, and indeed has feelings.

You might want to also read the articles first.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

He's a Koward, get it!

Re: Kode KDE Kindly, Kan You?

Terry's picture

Well, I thought it was an excellent article.

Considering the schmoe who wants to toss around names dosn't have the guts to sign his own flame...

***** him!

As far as the kNaming Konvention... I'll agree with both sides. It's kinda dumb on the surface, but it is usefull. Of course your free to gname gyour gKDE gapplications gany gway gyou gwant. ;>)

Peace,

Terry.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

Yes, it looks stupid, but is quite practical.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

I agree. When I read the Freshmeat updates, I can easily jump over everything that starts with a K. :)

But naming is something there where always around: who remember all that programs "for Windows"? Or PM-something or Something/2? Or even Xsomething? Althought some of them are really stupid, it is simpler to recognize what operating system or toolkit the program uses.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

motif has been open for about 2yrs...

www.openmotif.org

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

But look at the license. It is only free for open source OS. So thast prohibits development on say Linux and then running the Application on Solaris, AIX, etc.

Re: Kode KDE Kindly, Kan You?

Anonymous's picture

> motif has been open for about 2yrs...

It seems to me it has also been irrelevent for at least that long. It has certainly been ugly for a very long time. At any rate since KDE and the follow up of GNOME Motif wasn't exactly giving up the farm by finally opening. If they had done it years ago they might be more than a footnote in history.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState