Home Documentation Download Examples Developer

# Compilation with libQGLViewer

These instructions assume that you have installed Qt and libQGLViewer. They detail how to compile a program that uses the libQGLViewer library.

They apply to the provided examples as well as to your own programs.

## Tuning the `.pro`

Qt uses a `.pro` file to tune the compilation settings. The one that comes with the examples is pretty involved since it tries to automatically detect a number of parameters, and it can be simplified for your projects. The three important variables that have to be set in order to use libQGLViewer are:

- `INCLUDEPATH` which must indicates where to find the QGLViewer's include files. Since the `#include`s use a `QGLViewer/qglviewer.h` syntax, the `QGLViewer` suffix should be omitted in this path: If libQGLViewer was installed in the `/xxx/yyy/QGLViewer` directory, you will set this variable to `INCLUDEPATH *= /xxx/yyy`.
- `LIBS` which tells that your program links with libQGLViewer. Use `LIBS *= -L/path/to/lib -lQGLViewer2`, where `/path/to/lib` is the path to the libQGLViewer lib, named `libQGLViewer2.{so|a|dylib}` or `QGLViewer2.lib` depending on your architecture.
- `QT` which lists the required Qt modules: `QT *= opengl xml` is a minimum.

Here is a simple although complete `.pro` (change the paths according to your configuration):

    TARGET = myViewer
    CONFIG *= qt opengl release
    QT *= opengl xml

    HEADERS = myViewer.h
    SOURCES = myViewer.cpp main.cpp

    INCLUDEPATH *= C:/Users/debunne/Documents/libQGLViewer-2.3.5
    LIBS *= -LC:/Users/debunne/Documents/libQGLViewer-2.3.5/QGLViewer -lQGLViewer2

## Compilation using the Qt OpenSource edition and MinGW

Launch the Qt command prompt from the Start menu. Then simply type :

    cd path\to\simpleViewer
    qmake
    mingw32-make
    simpleViewer

Some `dll`s need to be found in order to run your program :

- `QGLViewer2.dll`, which has been created when you compiled the QGLViewer library.
- The Qt libraries (`QtCore4.dll, QtGui4.dll, QtOpenGL4.dll` and `QtXml4.dll`), which standard location is `C:\Qt\4.x.x\bin`.
- The MinGW `mingwm10.dll`, usually located in `C:\Program Files\MinGW\bin`.

Copy them to the executable's directory, or share them in a standard library directory such as `C:\Windows\System32`.

If you used the libQGLViewer installation package, these `dll`s were installed in `C:\Program Files\libQGLViewer\examples`.

See also the advices for libQGLViewer installation on Windows.

## Compilation using the Qt Commercial edition with Visual Studio integration

Launch Visual Studio from the Qt folder in the Start menu and then use the Qt menu to open the `.pro` file. All parameters should be properly configured, and your program should compile.

See the comment in the above section about `dll`s if you have an error when starting your program.

See also the advices for libQGLViewer installation on Windows.

Instead of editing the `.pro`, you can add the QGLViewer's headers path (without the trailing `QGLViewer`) to C/C++ / General / Additional Include Directories and add `QGLViewer2.lib` to the Linker / Input / Additional Dependencies using the project properties. These settings can also be shared by all your projects by setting the Tools / Options / Directories Include and Library values.

A `fatal error C1083: 'QDomElement' : No such file or directory` is fixed by adding `XML library` and `OpenGL library` in Project - Add Qt module.

With Visual Studio 6, use File-Open workspace to open the `.dsp` generated by `qmake` from the `.pro`.

## Compilation on Linux

Using the Unix command line, the compilation is as simple as:

    cd path/to/simpleViewer
    qmake
    make
    simpleViewer

You may be prompted with an `error while loading shared libraries` message when executing the program. Either copy `libQGLViewer.so` (created when you compiled the QGLViewer library) to this directory, or (better) move it to a standard library directory (such as `/usr/lib`, as is done when you `make install`).
If you don't have sufficient privileges to do that, you can also add the path to the `libQGLViewer.so` to your default library path (use `LD_LIBRARYN32_PATH` instead on some Unix flavors):

    [bash] > export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/path/to/qglviewerlib
    [tcsh] > setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/path/to/qglviewerlib

Some configurations may require you to add `LIBS *= -lXi` in the `.pro` file. Debian users may have to replace `-lQGLViewer` by `-lQGLViewer-2` in their `.pro`.

See also the Qt-Unix and libQGLViewer on Unix installation pages.

## Compilation on Mac

### Using Xcode

    cd path/to/simpleViewer
    qmake -spec macx-xcode

Then open and build the resulting Xcode project.

### Using `make`

    cd path/to/simpleViewer
    qmake -spec macx-g++
    make
    simpleViewer

### Next steps

You will have an error message if the libQGLViewer library is not found at runtime. Either install it in a standard directory (see the installation page) or use `install_name` to set its path in your program.

Read Apple's "Creating a Framework" as well as Qt's "Deploying an Application on Mac OS X" guides for details.

## Going further

Now that your program compiles and runs, you can start improving it. You will probably start by changing the `draw()` method to define your own scene. Overload the `init()` function to initialize your scene as well as the OpenGL parameters (such as textures and objects). Read the principles of the library for details. If not already done, try out the different examples and feel free to cut and paste code for the functionnalities you need.

## Localizing your application

See the Qt Linguist Manual for an explanation of the Qt translation model. Here are the lines you typically need to add in your `main` method to translate the texts of your interface.

      QApplication application(argc,argv);

      QString locale = QLocale::system().name();

      QTranslator translator;
      translator.load(QString("qglviewer_") + locale);
      // translator.load(your application specific translation file(s));
      app.installTranslator(&translator);

This assumes that `qglviewer_*.qm` is located in your application directory. If it is not the case, copy it or use the overloaded `load` method:

      translator.load(QString("qglviewer_") + locale, "C:\\Users\\debunne\\Documents\\Code\\libQGLViewer\\QGLViewer"); // for instance

QGLViewer translation files are available in the QGLViewer's header directory.

Please let me know if you encounter any problem following this guide.

Last modified on Sunday, February 28, 2010.