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 assume you created a folder for your project (probably a copy of one of the examples), with your sources and a project file.

windows         mac         linux

windowsCompilation on Windows

Using Qt Creator

Open in Qt Creator then compile and run.

Using make

Launch the Qt command prompt from the Qt folder in the Start menu. Then type:
cd path\to\myApp

Using Visual Studio

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. Make sure you link with the Release version of Qt if you build in Release mode.
With Visual Studio 6, use File-Open workspace to open the .dsp generated by qmake from the .pro.

Providing QGLViewer2.dll

The QGLViewer2.dll (or QGLViewer2d.dll in debug mode) has to be found in order to execute your application.
See also how to customize your .pro or the advices for libQGLViewer installation on Windows.

macCompilation on Mac

Using Qt Creator

Open in Qt Creator then compile and run.

Using Xcode

cd path/to/myApp
qmake -spec macx-xcode
open myApp.xcodeproj
Then compile your project.

Using make

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

Path customization

The standard installation will install the libQGLViewer framework in ~/Library/Frameworks, where it can be accessed from any application.

Use install_name and read Apple's "Creating a Framework" as well as Qt's "Deploying an Application on Mac OS X" if you customize your path.

Use the LIBS *= -L/path/to/lib -lQGLViewer Unix syntax if you compiled a dylib instead of a framework.
See also how to customize your .pro or the libQGLViewer on Mac installation page.

linuxCompilation on Linux

Using Qt Creator

Open in Qt Creator then compile and run.

Using make

cd path/to/myApp
libQGLViewer uses the -Wl,-rpath syntax so that your executable finds the library. In case you are prompted with an error while loading shared libraries message when executing the program, fix that path. An other option is to copy (created when you compiled the QGLViewer library) to your app's 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 how to customize your .pro or the libQGLViewer on Unix installation page.

Customize the .pro for your application

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. There is no need to change it: the examples should compile out of the box.

However, you can create a simplified .pro for your own projects. You need to set these three important variables in order to use libQGLViewer: 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

# Windows
INCLUDEPATH *= C:/Users/login/Documents/libQGLViewer-2.9.1
LIBS *= -LC:/Users/login/Documents/libQGLViewer-2.9.1/QGLViewer -lQGLViewer2

# Linux
INCLUDEPATH *= /home/login/Documents/libQGLViewer-2.9.1
LIBS *= -L/home/login/libQGLViewer-2.9.1/QGLViewer -lQGLViewer

# Mac 
INCLUDEPATH *= /Users/login/Documents/libQGLViewer-2.9.1
LIBS *= -F/Users/login/Library/Frameworks -framework QGLViewer
If you use Visual Studio, 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.

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 state (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 functionalities 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));
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\\login\\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 Thursday, December 29, 2022.