Compilation with libQGLViewer

Now that you have installed Qt and libQGLViewer, these instructions detail how to compile a program that uses the libQGLViewer library.

They apply to the provided examples as well as to your own programs (whose code will probably start from one of these, simpleViewer being the simplest one).

Tuning the .pro

The compilation settings are set using the .pro file in Qt. The one that comes with the examples should not need to be modified. It is pretty involved since it tries to automatically detect a number of parameters, and it can be simplified. The three important variables that have to be set in order to use libQGLViewer are: Here is a typical .pro (change the paths according to your configuration):
TARGET = simpleViewer
CONFIG *= qt opengl release
QT *= opengl xml

HEADERS = simpleViewer.h
SOURCES = simpleViewer.cpp main.cpp

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

Compiling and running your program

windowsUsing the Qt OpenSource edition with MinGW

Launch the Qt command prompt from the Start menu. Then simply type :
> cd path\to\simpleViewer
> qmake
> make
> simpleViewer
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 are available (standard installation path is C:\Program Files\libQGLViewer\examples).

See also the advices for libQGLViewer installation on Windows.
 

windowsUsing the Qt Commercial edition with Visual Studio integration

Launch Visual Studio from the Qt folder in the Start menu and 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.

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.

See also the advices for libQGLViewer installation on Windows.




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, asis 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}:/.../.../...
[tcsh] > setenv LD_LIBRARY_PATH \${LD_LIBRARY_PATH}:/.../.../...
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.





mac The compilation on Mac is essentially identical to the one described above in the linux section (libQGLViewer.so is named libQGLViewer.dylib instead). Simply replace the above lines by:

[bash] > export DYLD_LIBRARY_PATH=\${DYLD_LIBRARY_PATH}:/.../.../...
[tcsh] > setenv DYLD_LIBRARY_PATH \${DYLD_LIBRARY_PATH}:/.../.../...
You can safely ignore the prebound warning. Building a prebound library creates overlapping address ranges. This requires further investigations and any help is more than welcome.

If you get a declaration of C function 'void qObsolete' conflicts with previous declaration or a template with C linkage error message, try to install libQGLViewer somewhere else:

cd QGLViewer
make uninstall
qmake INCLUDE_DIR=/usr/local/include (for instance)
make install
Tune your .pro accordingly and recompile your program. Any explanation or cleaner solution is more than welcome.

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

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 Monday, August 31, 2009.