Installation of Qt 5 in Ubuntu
Qt requires g++ for other supporting packages. Refer to install-ubuntu for more information.

Download Qt 5 installation package from download site into a local directory, e.g., /home/me/Downloads.

   wget http://download.qt.io/official_releases/qt/5.4/5.4.1/qt-opensource-linux-x64-5.4.1.run


Run the installer and follow instructions in the installer:

   cd /home/me/Downloads
   chmod +x qt-opensource-linux-x64-5.4.1.run
   ./qt-opensource-linux-x64-5.4.1.run

In the installer, you can specify the directory in which to install Qt 5. To install in the default directory, e.g., /opt/Qt5.4.1, you need to run the installer with administer's right:

   sudo su
   ./qt-opensource-linux-x64-5.4.1.run

By specifying an installation directory different from that for Qt 4, which you may already have, you can have both Qt 5 and Qt 4 in your system.

After installing, add command directory to PATH in your .bashrc located in your home directory.

   PATH=.:/opt/Qt5.4.1/5.4/gcc_64/bin:$PATH

The command directory contains qmake, assistant, designer, etc. On the other hand, Qt Creator is kept in /opt/Qt5.4.1/Tools/QtCreator/bin.

For more details about installing Qt 5, refer to Qt 5 Installation Guide.
 
Transition from Qt 4 to Qt 5
Some common changes are illustrated here.

Header Files

Change

   #include <QtGui>

to

   #include <QtWidgets>

Sometimes, you may need to be more explicit, e.g.,

   #include <QtWidgets/QToolButton>

Compilation

In your source directory, run

   qmake -project

Edit the *.pro file and add

   QT += widgets

Then, run

   qmake
   make


A more convenient way is to create a new script file in your home directory say /home/me/qmakepro

   #!/bin/bash
   qmake -project "QT += widgets" $@


Then, run

   qmakepro
   qmake
   make


toAscii() and fromAscii()

The methods toAscii() and fromAscii() are deprecated. Replace them by

   fromLatin1()
   toLatin1()


QTimer

QTimer has 3 accuracy types and a new default:
* New default: Qt::CoarseTimer allows 5% difference to reduce power consumption, and allows timer to fire before requested time.
* Previous default: Qt::PreciseTimer is accurate to millisecond and never fires before requested time.
* New type: Qt::VeryCoarseTimer allows for 1 second difference.

For more details, refer to Qt 4 to Qt 5 Transition Guide.
 
Installation of Qt 4 in Ubuntu
Qt requires g++ for other supporting packages. Refer to install-ubuntu for more information.

The easiest way to install Qt 4 in Ubuntu is as follows:

   sudo apt-get install libqt4-dev
 
Compiling Qt 4 Programs
The most convenient way to compile Qt programs is to use qmake as follows.

In the directory that contains the .cpp files, run

   qmake -project

to create a .pro project file. You may need to edit the .pro file if certain include paths or library paths are missing. Next, run

   qmake
   make

The first command invokes qmake to create the makefile which make uses to compile the program.

For more information about qmake and its support for Qt, refer to the online qmake manual.
 
Compiling Qt and VTK Programs
To use VTK with Qt, first install VTK with Qt support.

One easy way to compile both Qt and VTK programs is to add the required VTK header files and library files into Qt project file.

(1) Create a separate Qt project file, say vtk.pro, to keep the required VTK header files and library files:

   QMAKE_CXXFLAGS += -Wno-deprecated
   INCLUDEPATH += /usr/local/include/vtk
   LIBS += -L/usr/local/lib/vtk -ldl -lGL -lvtkCommonColor -lvtkCommonCore \
      -lvtkCommonComputationalGeometry -lvtkCommonDataModel -lvtkCommonExecutionModel \
      -lvtkCommonMath -lvtkCommonMisc -lvtkCommonSystem -lvtkCommonTransforms -lvtkFiltersCore \
      -lvtkFiltersExtraction -lvtkFiltersGeneral -lvtkFiltersGeometry -lvtkFiltersHybrid \
      -lvtkFiltersSources -lvtkFiltersStatistics -lvtkImagingCore -lvtkImagingColor \
      -lvtkImagingFourier -lvtkImagingMath -lvtkImagingMorphological -lvtkImagingStencil \
      -lvtkIOCore -lvtkIOGeometry -lvtkIOImage -lvtkIOPLY -lvtkInteractionStyle \
      -lvtkInteractionWidgets -lvtkGUISupportQt -lvtkRenderingCore -lvtkRenderingOpenGL \
      -lvtkRenderingQt -lvtkRenderingVolume -lvtkalglib -lvtkjsoncpp -lvtksys -lvtkzlib


     The first line tells the compiler not to display warning messages for use of deprecated C++ functions by VTK.
     The second line includes the directory of VTK header files. The third line adds the required VTK library files.

(2) Run qmake -project to generate the application's project file, say myapp.pro.

(3) In the application's project file myapp.pro, add the following line before the HEADERS list:

   include(vtk.pro)

(4) Run qmake to generate the Makefile, which includes the VTK header directory and library files.

(5) Run make to compile and link the programs.
 
Troubleshooting
Gtk-Warning: Unable to locate theme engine in module_path: "pixmap"

This problem may occur when you run qtdemo, which is probably using GTK. To fix this problem, install the gtk2-engines-pixbuf package:

   sudo apt-get install gtk2-engines-pixbuf
 
Documentation
For online documentation, browse Qt Developer Network's documentation.

For offline documentation of Qt, run the Qt Assistant assistant. If necessary, install qt4-doc or qt4-dev-tools to install the documentation files:

   sudo apt-get install qt4-doc
or
   sudo apt-get install qt4-dev-tools
 
Qt Development Tools
Qt comes with design and development tools that can be easily installed from Ubuntu Software Center:
* Qt Designer: interface design
* Qt Creator: integrated development environment
* Qt Linguist: translation tool
* Qt Settings: Qt configuration tool