views:

437

answers:

3

I recently started looking into Qt (I installed Qt 4.5.2 and installed their Eclipse-CDT plugin called "qt integration v1.5.2" and I will do all my development in Linux-Eclipse-CDT-QTintegration).

Originally I thought Qt was a straight vanilla C++ library but when I installed and started running Qt example code I saw lots of "weird" things that I consider to be non-standard.

My goal is to understand at a high level of abstraction:

  • Is Qt classified as a C++ library?
  • If not a library, how would you classify Qt (analogy/metaphors are appreciated)?
+2  A: 

Qt is a set of C++ libraries along with a preprocessor and part of a build system.

Amuck
+1 Also can be considered a "development platform", meaning you can build your whole app from the libraries Qt provides.
Shaun
+17  A: 

Qt is a framework, not a library. This isn't a hard-and-fast distinction enforced by the programming language, rather, it describes how the code is designed and intended to be used:

A library is someone else's code that is used by your code. Using a library means that your application remains as it is, it just has another library to help it out.

A framework is someone else's code that your code fits into. Using a framework means that the framework defines the structure of your application.

If you're using a framework, you need to learn that framework's conventions, which may be a bit different than the base language; otherwise, you can spend a lot of time fighting the framework, and you'll be missing out on some of what it has to offer.

Qt in particular doesn't look like straight vanilla C++ because it isn't straight vanilla C++. It adds (limited) extensions to C++'s object system to permit features like signals and slots; these extensions are implemented using Qt's moc, which acts as a C++ preprocessor. For more information on Qt's extensions to C++:

Josh Kelley
+1  A: 

Most gui frameworks/libraries add to the language, just because C++ doesn't (or didn't until very recently) natively support the kind of events you need for a gui.

Qt chooses to do this with extentions to the language and a pre-compiler, MFC and wxWidgets do this with c macros and the c-preprocessor. The Qt approach means it can do more (it's not limited by the cpp macro language) at the expense of a slightly more complicated build environment.

Martin Beckett