Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

Getting Started

[ Home ] [ Next: Preparing to Migrate the User Interface ]

Starting with QMotif and QApplication

To be able to use Qt, we need to create a QApplication object. The QApplication class controls all the event delivery and display management for all other Qt objects and widgets. We need to use the QMotif class from the Qt Motif Extension to allow QApplication and the XtAppContext to coexist.

The QApplication object must be created in the main() function. We will need to modify todo.c to compile with a C++ compiler, so we rename todo.c to todo.cpp.

Next, we add the appropriate includes for the QMotif and QApplication classes.

Next, we create the QMotif and QApplication objects. We create QMotif with a foreign XtAppContext, and we create QApplication with a foreign Display.

The next change is not yet necessary, but it is included to show that the Qt Motif Extension provides a complete integration. Normally, a Motif based program would use the XtAppMainLoop() function to run the application's event loop. This is still possible, but since we are migrating to the Qt toolkit, we prefer to use the QApplication::exec() function for running the event loop.

Since we renamed todo.c to todo.cpp, we must change the project file and rerun qmake to regenerate our Makefile. When we build our project, there are compile and link errors: we will fix these in the following section.

Migrating to C++

We need to convert the code in this file to proper C++ code. Fortunately, the changes are not too large. Most files included from existing C projects are not C++ compatible, so we make them compatible by wrapping them in an extern "C" block.

Global C functions that are forward declared must also be wrapped into an extern "C" block.

The manageCB() function needs to be converted to proper C++.

And we need to fix two invalid casts. One is in the Save() function.

The other invalid cast is in the Open() function.

After these changes, the project compiles and links, and the application runs and operates correctly.

[ Home ] [ Next: Preparing to Migrate the User Interface ]

Copyright © 2005 TrolltechTrademarks
Qt 3.3.7