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

Getting Started

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

Starting with TQMotif and TQApplication

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

The TQApplication 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 TQMotif and TQApplication classes.


Next, we create the TQMotif and TQApplication objects. We create TQMotif with a foreign XtAppContext, and we create TQApplication with a foreign Display.


The next change is not yet necessary, but it is included to show that the TQt 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 TQt toolkit, we prefer to use the TQApplication::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 © 2007 TrolltechTrademarks
TQt 3.3.8