Programming graphically with Qt.

Qt is a commercial package that was adopted by the original programmers of the KDE desktop environment. If you like KDE, you probably will like Qt as well.
Qt was made by a norwegian company called Trolltech and it is donated to the Linux community under a special licence.

An example Qt source.

Below is a first piece of Qt source. It is 'not so easy C'. In fact, it is the dreaded C++. See if you can understand what's going on in it:

#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
#include <qfont.h>
#include <qlabel.h>

class MainWindow : public QWidget

{
 public:
   MainWindow ();
 private:
   QPushButton *b1;
   QLabel *label;
};


MainWindow::MainWindow ()

{
   setGeometry (100, 100, 300, 170);

   b1 = new QPushButton ("Quit", this);

   b1->setGeometry (20, 20, 160, 80);
   b1->setFont (QFont ("Clean", 18, QFont::Bold));

   label = new QLabel (this);

   label->setGeometry (20, 110, 250, 50);
   label->setText ("If you click on the button\nyou will kicked back to X");
   label->setAlignment (AlignCenter);
   
   connect (b1, SIGNAL (clicked () ), qApp, SLOT (quit () ) );
}

void main (int argc, char **argv)
{
   QApplication a (argc, argv);

   MainWindow (w);
   a.setMainWidget (&w);
   w.show ();

   a.exec ();
}
   
Compile this source (I called it fff.cpp) with the line:
 gcc -lqt fff.cpp -o fff
   
to make an executable called 'fff' out of the sourcefile 'fff.cpp'.

As you can see, this is a whole other story than GTK. To be honest I must admit that this source is much better to read and understand, be it on the surface only, for the time being.
Making of the buttons is easier, puttings labels in them: same conclusion. The signals are easier to connect to a slot. No lines choc full of CAPITAL_AND_UNDERSCORED words. It's easier on the eye.

In the download section I included all the source code examples from the book that I entered until now. Use them for your own purposes. But remember: no guarantee on the files. You do the compiling.

Qt designer and KDE developer.

Today (6 May 2009) I tried Qt Designer and KDE developer. Lots of documentation available on my system for both of them. So the dox were open in the SeaMonkey browser and in another desktop I was running K Develop. The documentation is good. It must have been a hell of a project, designing Qt designer (Troll Tech) and K Develop (KDE team). And still it was like trying to swim in cold molasses. You may be able to walk on it, but swim IN it? Very hard to do.

After 20 odd minutes I got the knack of it: I could open the sample project file. Then I needed to compile the empty sources! And make a project out of it. All in all the new project (saying Hello Thingy) was installed in a complete source FOREST! Not one single tree but lots of them!

I didn't do anything by myself upto now but I already spent more time on this void than in the first 10 Modula-2 programs I made... For some reason, this graphical programming is too complex for me. No matter what you use, but as soon as you enter the realm of Qt or X11, things get hairy. Even the smallest graphical object has a million properties and features.

I just need some buttons, spinboxes and text entry fields. That's all! I don't want to spend 1000's of lines of code to get that done. And then build, make, configure, execute. Why so complicated? Why so serious? Let's put some smile on that face!
That smile is called 'Tk'. When I look at the results of the sample projects of Qt designer and K Develop, I see something that looks like a Tcl/Tk program, with the difference that the latter looks better and is easier to make and understand.

I guess I was born too early (1956).

Page created June 2004,

Page equipped with FroogleBuster technology