Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

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 ]

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 3.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web