18.4. Qt

Open Inventor consists of a portable core component and various window system-specific components:

This chapter describes the Open Inventor portable window-system components for the Qt environment, specifically the SoQt classes.

Qt is a cross-platform C++ GUI application framework from Trolltech AS. See www.trolltech.com for more information.

Open Inventor was designed to be portable and window system independent. Like OpenGL it uses a large core of system-independent classes and a small set of window system-specific classes. The SoXt classes are specific to the X Windows/ Xt/ Motif environment (Unix/Linux). The SoWin SoWin classes are specific to the Microsoft Windows environment. The SoQt classes are specific to the Qt environment, but Qt is itself window system independent. So the combination of the Open Inventor core, SoQt classes, and Qt allows a single application source code to build and run on many different platforms, including both Unix/Linux and Microsoft Windows.

There is a close correspondence between the SoXt , the SoWin SoWin , and the SoQt classes. Thus, it is very easy to port an SoXt or an SoWin SoWin Inventor program to a portable SoQt program.

As usual, it is easier to begin with a simple example. Here is a simple Open Inventor program from Chapter 2 of The Inventor Mentor (Example 2.4, “ “Hello, Cone” Using the Examiner Viewer). This program has been translated into Qt by simply replacing the SoXt calls with SoQt calls.

This program works essentially the same as it would with SoXt and SoWin SoWin . Calling SoQt ::init with a string creates a QApplication and its main window, and returns its window handle. The viewer’s window is created as a child of the main window. The “ show ” call makes the various windows visible and the SoQt ::mainLoop provides the Qt event loop.


The SoQt class initializes Inventor for use with all supported systems. All of its methods are static convenience functions. Every SoQt class includes all the methods of its corresponding SoWin SoWin and SoXt class. Generally these methods have the same or similar behavior. In a few cases the data types have been changed for the Qt environment. In particular:

SoWin SoWin

SoXt

SoQt

HWND

Window and Widget

QWidget *

MSG

XEvent

QEvent

SoQtComponent is the abstract base class for all Open Inventor components. Some of the functions were already defined in the QWidget class but are still defined for compatibility reasons, like show(), hide(), isVisible(), setFullScreen(), or setTitle(). Others are typical Open Inventor component functions like getWidget(), getWidgetName(), getClassName(), etc. The getDisplay() method is for use on Unix only.

[Important]

Help files are handled differently on Windows and Unix/Linux. On Windows, SoQt opens a CHM help file (VC++ 6.0) or a Help 2.0 file (VC++ 7.1 and newer). On Unix/Linux, it opens the HTML help documentation.

SoQtGLWidget is the generic component for OpenGL rendering. SoQtGLWidget uses QGLWidgetfrom Qt.

Windows

Unix

Qt

HGLRC

GLXContext

QGLContext

PIXELFORMATDESCRIPTOR

XVisualInfo

QGLFormat

This part describes how to implement a Qt application using SoQt classes. Good examples to look at to understand this part are the QtLargeModelViewer or the QtTreeView examples (located in $OIVHOME/src/Inventor/examples/Qt).

Note for SoWin SoWin and SoXt users: Qt will delete all the widgets when the application is closed.

Open Inventor provides a plugin for Qt Designer. This plugin extends the set of available widgets in Qt Designer so that an Open Inventor 3D viewer can easily be integrated into the application’s user interface.

The directory $OIVHOME/OpenInventor/OIV/src/Inventor/examples/Qt/Plugin contains the files necessary to build Qt Designer plugin library, including project and source files:

On Windows, the plugin DLL is automatically created by the Open Inventor SoQt installer (the tool that builds SoQt after Open Inventor has been installed) and will be placed in the designer plugin directory (for example, %QTDIR%\plugins\designer).

On Unix or Linux, you must build the plugin library yourself, using the supplied makefile. The makefile will copy the library into the designer plugin directory (for example, $(QTDIR)/plugins/designer).