1.0 Introduction

2.0 Component Object Relationships

3.0 Steps to Building an Application with Qt and HOOPS

3.1 Creation and Initialization of Qt Objects
3.2 Creation and Initialization of HOOPS/Qt Objects
3.3 Creation and Initialization of HOOPS/MVO Objects
3.4 Launching the Qt Event Loop


1.0 Introduction

The following section explains how to build an application with the Qt GUI toolkit and the HOOPS 3D Application Framework. First the relationships of the objects in the various components are described, followed by a list of programming steps needed to correctly create and initialize the objects and launch the Qt Event Loop.

Developers should start by compiling, linking and running the basic qt_simple application as the starting point for their application. This is just a skeleton application the readable source code to which is located in the demo/qt/qt_simple directory of your HOOPS installation. This applicaiton is the one you should use if you intend on completing the tutorials in this section. There are a number of other more sophisticated Qt applications included in the Qt directory which you can use as a source of reference as you add functionality to your applciation.

The code has been commented and hyper-linked to the Qt and HOOPS/3dAF documentation. Familiarity with both the Qt toolkit and HOOPS/3dAF is assumed.

2.0 Component Object Relationships

This section discusses the relationships between the objects in the various Qt and HOOPS/3dAF components. Building an application with both these toolkits minimally involves using the following objects from each component:

Qt

Only one QApplication & at least QMainWindow (or derived class)

HOOPS/Qt

At least one MyHQWidget (derived from HQWidget)

HOOPS/MVO

HBaseModel, HBaseView, an Operator class derived from HBaseOperator.  Applications that want to implement selection of Geometry will also need a HSelectionSet object. 


These objects are all connected by private data members which store pointers to other objects in the following manner:

 


 


3.0 Steps to Building an Application with Qt and HOOPS

Programming with an object oriented GUI framwork like Qt involves creating a set of objects, defining the ways in which they are connected, the manner in which they send and receive messages, and then launching the framework's event loop. Building an application using Qt and the HOOPS/3dAF specifically requires the following steps in this order:

 

3.1 Creation and Initialization of Qt Objects

QApplication
For any GUI application that uses Qt, there is precisely one QApplication object no matter how many windows the application has.  It can be accessed via the global variable qapp, declared in QApplication.h, which must be initialized prior to the creation of any other Qt objects. The HOOPS/Qt Reference Application performs this in the function main ( ). (Go there.)

Color Allocation and GUI Style

The QApplication object's attributes for color allocation and GUI Sytle must be configured.  For Qt/HOOPS applications the color allocation must be set to "ManyColor".  The GUI Style is used to choose between Motif or Windows styles for the visual appearance and default behavior of the Qt GUI created. (Go there.) 

3.2 Creation and Initialization of HOOPS/Qt Objects
 

HQApplication

One HQApplication object should be created using the constructor that accepts a pointer to a Qt QApplication object. The HOOPS/Qt Reference Application performs this in the function main ( ). (Go there).

The HQApplication object should create any Qt GUI object's to be parented off of it during its initialization. The HOOPS/Qt Reference Application performs this when a HQApplication object is being initialized by calling its private method HQApplication::load (const char * filename)


MyHQWidget

As many MyHQWidgets can be created as needed to implement the GUI's design. These are more than likely going to be created by a constructor of a top level Qt Widget like QMainWindow or QDialog. The HOOPS/Qt Reference Application performs this when a HQApplication object is initialized by calling its private method
HQApplication::load (const char * filename)

HQDeleter

One global pointer must be declared and initialized in the application code block. The HOOPS/Qt Reference Application performs the global declaration in the file main.cpp (Go there) and the initialization in the body of the function main ( ). (Go there.)
 

3.3 Creation and Initialization of HOOPS/MVO Objects
 

HDB

One global pointer to a HOOPS/MVO HDB object must be declared and initialized in the application code block. the HOOPS/Qt Reference Application performs the global declaration in the file main.cpp (Go there) and the initialization in the body of the function main (). (Go there.)

HBaseModel

Multiple HBaseModel objects can be created as needed. The HOOPS/Qt Reference Application creates one for every MyHQWidget object, i.e., there is a one-to-one mapping of HBaseModel to MyHQWidget objects.
The creation of the HBaseModel occurs in the MyHQWidget's constructor. (Go there.)
 

HBaseView

Multiple HBaseView objects can be created as needed. The HOOPS/Qt Reference Application creates one for every MyHQWidget object, i.e., there is a one to one mapping of HBaseView to MyHQWidget objects. It is also possible to have multiple HBaseViews associated with one HBaseModel (i.e., multiple views of the same model) and vice versa (multiple models in the same view.)

The HBaseView needs a valid window id and colormap passed to its constructor on object creation; information used to connect a HOOPS/3dGS output driver instance to a Qt QWidget. This requires that the QtWidget, to which the HBaseView will be attached, must already exist prior to creating the HBaseView object.

The HOOPS/Qt Reference Application creates one HBaseView object per MyHQWidget instance in the virtual methodMyHQWidget's::Init( ). This method is called by the base class HQWidget in the method HQWidget::paintEvent () the first time it is called ensuring that the widget is alive and thus the Window ID is valid and the HBaseView object can be created.


HBaseView's Current Operator

The HBaseView class has a member HBaseView::current_operator that is a pointer to an HBaseOperator object. A default operator must be created and used to initialize the HBaseView's current operator member. The HOOPS/Qt Reference Application does this in the method MyHQWidget's::Init( ).

HSelectionSet

Multiple HSelectionSet object can be created as needed. The HOOPS/Qt Reference Application creates one for every MyHQWidget object, i.e., there is a one to one mapping of HSelectionSet to MyHQWidget objects. The creation of the HSelectionSet occurs in the method MyHQWidget's::Init( ).

3.4 Launching the Qt Event Loop

This is performed by calling the QApplication's method QApplication::exec (). The HOOPS/Qt Reference Application performs this in the function main (). (Go there.)