Wednesday 25 August 2010

Beginning with Qt: Introduction, Installing Qt Framework, Qt Hello world

INTRODUCTION TO Qt

Qt is a complete development environment widely used to create GUI applications.

This cross-platform tool is also able to create non gui apps.

Qt is used in the KDE desktop environment, and in other projects like virtualbox.


Qt development environment provides: (version numbers when this article was written)

  • Qt libraries (version 4.6.3)
  • Qt Creator IDE (version 2.0.0)
  • Qt development tools


Qt is available under LGPL and GPL free software licenses. Nokia also provides the Qt commercial license to develop proprietary software.


Qt DEVELOPMENT TOOLS

Qt environment provides us with some development tools. e.g:

qmake
qmake tool helps us creating and managing .pro project files, and from them it creates Makefile files needed to build our projects.
qmake Manual
qmake Tutorial

Qt assistant
Qt assistant tool shows all available Qt help. It is a help browsing system.
Qt Assistant Manual

Qt designer
Qt designer helps creating gui applications in an intuitive and easy way instead of dealing directly with the code.
Qt Designer Manual

Qt demo
Shows in a graphic manner some demos displaying all Qt capabilities.

moc : The Meta-Object Compiler, is the program that handles Qt's C++ extensions. It substitutes macros producing C++ source code.
If we use qmake tool we do not have to deal directly with moc tool.

uic : User Interface Compiler. The uic reads an XML format user interface definition (.ui) file as generated by Qt Designer and creates a corresponding C++ header file.

There are other tools like Qt linguistics, etc.


DOWNLOAD Qt

We are going to install Qt framework (i.e: library and some development tools) from source code.

Qt source code is available in this web page:
http://qt.nokia.com/downloads/downloads#lgpl

My system is a Debian GNU/Linux one, so I choose Qt libraries 4.6.3 for Linux/X11(161 MB).


NOTE: We could install Qt using the debian packaging system. e.g:
$ aptitude search qt4 # To search for Qt4 packages in Debian.


Install Qt in X11 systems

After downloading the tarball we uncompress it:
$ tar xvzf qt-everywhere-opensource-src-4.6.3.tar.gz
$ cd qt-everywhere-opensource-src-4.6.3

In order to build Qt library we have to satisfy some dependencies:
http://doc.trolltech.com/4.6/requirements-x11.html


BUILD Qt FRAMEWORK AND INSTALL IT

$ ./configure
Select open source qt edition. Accept it.
$ make # it will take a lot of time.
# make install # As root.
It will install by default in /usr/local/Trolltech/Qt-4.6.3 directory.

NOTE: In my machine Qt source directory becomes 3 Gigabyte in size, and Qt installed directory reaches 1G.

Customizing env shell variables
Add tools dir to PATH variable:
$ PATH=/usr/local/Trolltech/Qt-4.6.3/bin:$PATH
$ export PATH


Test if Qt library was correctly installed.
$ which qmake # test if qmake is in the path.
/usr/local/Trolltech/Qt-4.6.3/bin/qmake
$ qmake -v
QMake version 2.01a
Using Qt version 4.6.3 in /usr/local/Trolltech/Qt-4.6.3/lib

Running some Qt dev. tools:
$ qtdemo # to run Qt demo.
$ assistant # to run Qt assistant (a Qt help viewer)
$ designer # to run Qt designer.


Tutorials and all Qt documentation are also appear within Qt library sources. i.e:
file:///path/to/qt-everywhere-opensource-src-4.6.3/doc/html/
file:///path/to/qt-everywhere-opensource-src-4.6.3/doc/html/tutorials.html


There also appears the source code to compile all Qt examples:
E.g: Build and compile some widgets examples:
$ cd qt-everywhere-opensource-src-4.6.3/examples/tutorials/widgets
$ qmake # creates a Makefile file using widgets.pro file as input.
$ make # compiles the examples.
$ toplevel/toplevel # executes some binary examples...
$ windowlayout/windowlayout


FIRST Qt HELLO WORLD APPLICATION

$ mkdir helloworld
$ cd helloworld

Create helloworld.cpp file (based on toplevel.cpp one):

#include 

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

// Create the window and resize it.
QWidget window;
window.resize(320, 240);

// Create a label showing hello world!
QLabel label("Hello, world!", &window);

// Show the window.
window.show();

// Set the window title.
window.setWindowTitle(
QApplication::translate("helloworld", "Hello World"));

return app.exec();
}


$ qmake -project # creates helloworld.pro file using some heuristics.
$ qmake # generates Makefile
$ make # builds helloworld project.
$ ./helloworld


Qt GENERAL AND USEFUL DOCUMENTATION

Qt Reference Documentation


Official - How to learn QT

Official QT 4.6 Tutorials

Widgets Tutorial

Application Example
The Application example shows how to implement a standard GUI application with menus, toolbars, and a status bar. The example itself is a simple text editor program built around QPlainTextEdit.



Qt examples sorted by categories.

Qt Widget Gallery

All Overviews and HOWTOs Overview of all Qt documentation.



Qt Demonstrations
This is the list of demonstrations in Qt's demos directory. These are larger and more complicated programs than the Qt Examples


Understanding Qt

Qt Object Model

Signals and Slots

The Graphics View Framework


Qt Mailing lists
http://lists.trolltech.com


Books about Qt
http://qt.nokia.com/developer/books


Official Qt web page
http://qt.nokia.com

2 comentarios:

Anonymous said...

Thank you very much! It is very helpful

Vicente Hernando said...

Your are welcome. :)