First steps in Qt

Qt is used mainly for developing application software with graphical user interfaces (GUIs); however, programs without a GUI can be developed, such as command-line tools and consoles for servers.
GUI programs created with Qt can have a native-looking interface, in which case Qt is classified as a widget toolkit.
Qt uses standard C++ with extensions including signals and slots that simplify handling of events, and this helps in development of both GUI and server applications which receive their own set of event information and should process them accordingly. Qt supports many compilers, including the GCC C++ compiler and the Visual Studio suite.
Qt also provides Qt Quick, that includes a declarative scripting language called QML that allows using JavaScript to provide the logic.
With Qt Quick, rapid application development for mobile devices became possible, although logic can be written with native code as well to achieve the best possible performance.
Qt can be used in several other programming languages via language bindings. It runs on the major desktop platforms and some of the mobile platforms.
It has extensive internationalization support. Non-GUI features include SQL database access, XML parsing, JSON parsing, thread management and network support.

Historic of Qt

  • Qt1
    • 1995 first public release
    • 1997 KDE launched by Matthias Ettrich.
  • Qt2 – 1999 Qt/Embedded / now Qtopia
  • Qt3 – 2001 – QT supported on MAC OSX
  • Qt4 – New rendering engine (Arthur7) – Qt is now composed with several modules :
    • QtCore : non graphical function used by toher modules
    • QtGui : graphic component
    • QtNetwork : networking module;
    • QtOpenGL : OpenGL module;
    • QtSql : Database access using SQL ;
    • QtXml : XML files management ;
    • QtDesigner : extend fucntionalities of Qt Designer, a wizard to create graphical user interface;
    • QtAssistant : for using Qt help;
    • Qt3Support : Backward compatibility with Qt 3.
    • QAxContainer et QaxServer : two other modules (dedicated for usage of ActiveX) for the commercial version of Qt for Windows.
      With evolution of Qt 4, others modules are created :
    • QtDBus : for process communication using D-Bus (only for Unix from Qt 4.2) ;
    • QtSvg : Manage SVG image from Qt 4.1;
    • QtUiTools : to load dynamicly the graphics user interface designed with Qt Designer from Qt 4.1 ;
    • QtTest : to make unit test from Qt 4.1 ;
    • QtScript : to evaluate scipts using Qt Script from Qt 4.3;
    • QtWebKit : porting of web rendering engine WebKit from Qt 4.4 ;
    • QtXmlPatterns : to manipulate XML documents via Xquery, Xpath from Qt 4.4 ;
    • Phonon : integration of Phonon, a multimedia framework of KDE 4, developped in collaboration with KDE community from Qt 4.4 ;
    • QtHelp , QtScriptTools , QtMultimedia , QtOpenVG and QtDeclarative : used to create dynamic graphic interface with a declarive language QML from Qt 4.7.
  • In 2008, Qt is buy by Nokia who introduce a new licence LGPL and open the development for external developpers ;
  • Qt5, released in 2012, no more compatbility with QT4.

QMake vs Cmake… And Qbs

Qmake & CmakeBoth are build systems, but they’re not very similar at all. If your project uses Qt, you’re probably best off using qmake. CMake is more generic, and fits pretty much any type of project.

Both qmake and CMake generate a Makefile, which is read by make to build the project. Not all build systems generate a Makefile, but many do. Even a Makefile is a type of build system; it tells the compiler and linker what to do, in order to create an executable (or a dynamic or static library).
Qmake

Qt is wanting a portable development environment and having the MOC as an intermediate step before building phase / linking, it was necessary to design a specific production engine. Thus was conceived the qmake program.
It takes an input file (extension .pro) describing the project (list of source files, dependencies, compiler flags, etc.) and generates a specific project file to the platform. Thus, under UNIX systems qmake generates a Makefile that contains the list of commands to be executed for generating an executable, except for specific steps to Qt (generation C ++ classes in the graphical interface design with Qt Designer generation C ++ code to link the signals and slots, adding a file to the project, etc.).

The project file is made to be easily editable by a developer. It consists of a series of variable assignments. An example for a small project:

TARGET = monAppli
SOURCES = main.cpp mainwindow.cpp
HEADERS = mainwindow.h
FORMS = mainwindow.ui
QT += sql

If your project uses Qt, but you don’t want to use qmake, you’ll have to do a few more things yourself:

running the Meta Object Compiler (MOC)
include paths (tell the compiler where to look for Qt headers)
linking (tell the linker where to look for Qt libraries)
So, you’ll have to do a bit more work to build a Qt project without qmake, but it is possible and it will teach you a lot about how Qt and qmake do things.

Exemple of using CMake for Qt projects. Specifically, we have the following in CmakeLists.txt:

set(QT_VERSION_REQ "5.2")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5Core ${QT_VERSION_REQ} REQUIRED)
find_package(Qt5Quick ${QT_VERSION_REQ} REQUIRED)
find_package(Qt5Widgets ${QT_VERSION_REQ} REQUIRED)
find_package(Qt5Gui ${QT_VERSION_REQ} REQUIRED)

set(CMAKE_AUTOMOC ON)
QT5_WRAP_UI( UI_HDRS ${UI_FILES} )

ADD_EXECUTABLE(${MOC_HEADERS})

target_link_libraries(${PROJECT_NAME}
 Qt5::Core
 Qt5::Quick
 Qt5::Widgets 
 Qt5::Gui 
)

QBS

Some words about qbs, which is supposed to be a better qmake.
Qbs is a tool that helps simplify the build process for developing projects across multiple platforms. Qbs can be used for any software project, regardless of programming language, toolkit, or libraries used.
Qbs is an all-in-one tool that generates a build graph from a high-level project description (like qmake or CMake) and additionally undertakes the task of executing the commands in the low-level build graph (like make).
Qbs builds applications based on the information in a project file that you specify in a QML dialect. Each project file specifies one project that can contain several products. You specify the type of the product: application, library, and so on.

Installation on Windows

The Windows installation is in the form of a conventional installation wizard that downloads new files before installing them.

Qt and Qt Creator

Although it is possible to develop in C ++ with Qt using our IDE (like Code :: Blocks) I highly recommend you to use Qt Creator IDE that we just installed. It is particularly optimized for developing with Qt because it is an all-in-one program which includes among others :
an IDE for developing C ++, optimized to compile projects using Qt (no tedious configuration);
a window editor, which makes it easy to draw the contents of the interfaces to the mouse;
an indispensable documentation on Qt.
Here’s what Qt Creator looks when you launch the first (figure below). You can start to try to compile and execute Qt Sample Application.

Qt creator, and a impressive list of samples !

 

The C++ Source Code on a Qt sample application.

 

A executable of Qt Sample : some 3D object