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 where the library and headers files are located. It can be simplified for your projects. The three important variables that have to be set in order to use libQGLViewer are: 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.6

# Windows
LIBS *= -LC:/Users/debunne/Documents/libQGLViewer-2.3.6/QGLViewer -lQGLViewer2

# Linux
LIBS *= -L/home/debunne/libQGLViewer-2.3.6/QGLViewer -lQGLViewer

# Mac if you compiled a framework in /Library/Frameworks (default)
LIBS *= -framework QGLViewer

windowsCompilation using the Qt OpenSource edition and MinGW

Launch the Qt command prompt from the Start menu. Then simply type :
cd path\to\myApp
qmake
mingw32-make
myApp
Some dlls need to be found in order to run your program : 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 dlls were installed in C:\Program Files\libQGLViewer\examples.

See also the advices for libQGLViewer installation on Windows.

windowsCompilation 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 dlls 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.

linuxCompilation on Linux

Using the Unix command line, the compilation is as simple as:
cd path/to/myApp
qmake
make
myApp
The use of -Wl,-rpath in the compilation options should make your executable find the library. In case you are prompted with an error while loading shared libraries message when executing the program, fix the path. An other option is to 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).
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.

macCompilation on Mac

Using Xcode

cd path/to/myApp
qmake -spec macx-xcode
Then open and build the resulting Xcode project.

Using make

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

Using Qt Creator

open myApp.pro 

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.

Tune the QMAKE_LFLAGS variable if the library was not installed in the default /Library/Frameworks directory. Use the LIBS *= -L/path/to/lib -lQGLViewer Unix syntax if you compiled a dylib instead of a framework.

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.

Valid XHTML 1.0! Valid CSS! Last modified on Saturday, May 22, 2010.