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( C++ ) 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( C++ )classes are specific to the X Windows/ Xt/ Motif environment (Unix/Linux). The SoWin( C++ | .NET )classes are specific to the Microsoft Windows environment. The SoQt( C++ )classes are specific to the Qt environment, but Qt is itself window system independent. So the combination of the Open Inventor core, SoQt( C++ )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( C++ ), the SoWin( C++ | .NET ), and the SoQt( C++ ) classes. Thus, it is very easy to port an SoXt( C++ ) or an SoWin( C++ | .NET ) Inventor program to a portable SoQt( C++ ) 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( C++ ) calls with SoQt( C++ ) calls.

This program works essentially the same as it would with SoXt( C++ ) and SoWin( C++ | .NET ). Calling SoQt( C++ )::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( C++ )::mainLoop provides the Qt event loop.


The SoQt( C++ ) class initializes Inventor for use with all supported systems. All of its methods are static convenience functions. Every SoQt( C++ ) class includes all the methods of its corresponding SoWin( C++ | .NET ) and SoXt( C++ ) 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( C++ | .NET )

SoXt( C++ )

SoQt( C++ )

HWND

Window and Widget

QWidget *

MSG

XEvent

QEvent

SoQtComponent( C++ ) 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( C++ ) 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( C++ ) is the generic component for OpenGL rendering. SoQtGLWidget( C++ ) uses QGLWidgetfrom Qt.

Windows

Unix

Qt

HGLRC

GLXContext

QGLContext

PIXELFORMATDESCRIPTOR

XVisualInfo

QGLFormat

This part describes how to implement a Qt application using SoQt( C++ ) 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( C++ | .NET ) and SoXt( C++ ) 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( C++ ) installer (the tool that builds SoQt( C++ ) 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).