Hello Qt with a color touch

Once installed both VC++ 2010 and Qt on my machine (not a top notch one, a lap top a couple of years old with the infamous Windows Vista on - but enough for having some fun), I started reading "C++ GUI Programming with Qt 4, Second Edition" by Jasmin Blanchette and Mark Summerfield. Looks like a good book on the matter.

I'm about to write down a few posts during my reading, hoping that that could be useful for someone else too. At least as an hint on wich book to buy to knowing more on Qt.

The first chapter of the book is all about writing an hello Qt program, so close to the one I wrote in the previous post on Qt that someone could even think it is just the same. Luckly it is shown also another variant, in which the label is set with a HTML formatted text. Quite cool, isn't it?

#include <QtGui/QApplication>
#include <QtGui/QLabel>

int main(int argc, char** argv)
{
QApplication app(argc, argv);
QLabel* label = new QLabel(("<h2><i>Hello</i><font color=red>Qt!</font></h2>"));
label->show();

return app.exec();
}

Actually, there is another difference in this hello Qt program, compared to the one in the previous post. Here we have a memory leak, since we put the label on the heap, and not on the stack, without deleting it when done with it. Is that a major problem? Well, no, it isn't, since we are just about to leave the main.

No comments:

Post a Comment