Using Qt Standard Dialogs[ Previous: Preparing to Migrate the User Interface ] [ Home ] [ Next: Using Custom QDialogs ]We start by using two of the Qt Standard Dialogs: QFileDialog and QMessageBox. Both of these classes provide useful static convenience functions.
Each of these functions takes a QWidget *parent argument. If we pass zero as the parent argument, then we will have dialogs that are centered on the screen, instead of being centered over our main window. We can have QMotifWidget create our XmMainWindow, and we can then use this class as the parent for both Motif dialogs and Qt dialogs. We need to include the appropriate headers for QMotifWidget and QFileDialog in todo.cpp.
Next, we make a few modifications to how the application is initialized. We could initialize Xt/Motif and create the XtAppContext ourselves, but QMotif can do this for us. We also let QApplication open the connection to the X server. Next, we create a QMotifWidget, passing xmMainWindowWidgetClass as the widgetclass argument. We can now use the QMotifWidget::motifWidget() function to access the Motif widget. The shell widget is created automatically by QMotifWidget. We use XtParent() to access it. The top-level window is now a QMotifWidget, which means we can use it as the parent for the Qt Standard Dialogs.
Replacing the Open and Save As DialogsFirst, we completely remove all use of the existing Motif file selection dialog. We remove the Xm/FileSB.h include, the global file_dialog variable, and the code to create the dialog. We also remove the PresentFDialog() callback function. None of this code is needed to use QFileDialog. After removing the PresentFDialog() callback function, we need to make Open and Save As popup-menu callbacks call the Open() and Save() functions. First we must change the declaration of these two functions.
We also change the arguments to the callbacks. We pass the top-level QMotifWidget as the client_data to these functions, since we will be using it as the parent for the QFileDialog.
...
Next, we modify the Save() function to use QFileDialog::getSaveFileName().
... and the Open() function to use QFileDialog::getOpenFileName().
After we build the project, the application runs and operates as expected. The difference is that the Open and Save As dialogs now use QFileDialog.
Replacing the Page Delete and IO Error DialogsThe Page Delete dialog is created and used in actions.c. We need to migrate this file to C++. We rename it to actions.cpp, modify the project file and regenerate the Makefile. The changes required to make actions.cpp compile are minimal. We need to wrap more C header files and global variables in an extern "C" block.
We need to forward declare the NewPage(), DeletePage(), EditPage() and SaveIt() functions so that the compiler generates the correct symbols for these functions.
We need to fix a single invalid pointer cast.
And we need to change the variable named new to newstr in the Trim() function. We can now change the DeletePage() function to use QMessageBox::information(). First, we need to make sure we include the proper header for QMessageBox.
The code for DeletePage() looks like this:
At this point in the code, the page should be deleted. The code to do this is in the DoDeletePage() function. We move the contents of DoDeletePage() to this point and remove the DoDeletePage() function completely. Next, we change todo.cpp to pass the top-level QMotifWidget as the client_data tot he DeletePage() function.
The IO Error dialog is created and used in io.c. We need to migrate this file to C++. We rename it to io.cpp, modify the project file and regenerate the Makefile. The changes required to make io.cpp compile are minimal. We need to wrap more C header files and global variables in an extern "C" block.
We need to forward declare the ReadDB() and SaveDB() functions so that the compiler generates the correct symbols for these functions.
The ParseNewLines() function needs to be converted to proper C++.
The PrintWithNewLines() function also needs to be converted to proper C++.
We can now change the ReadDB() and SaveDB() functions to use QMessageBox::warning(). First, we need to make sure we include the proper header for QMessageBox.
The code for ReadDB() looks like this:
... The code for SaveDB() looks like this:
... After we build the project, the application runs and operates as expected. The difference is that the Page Delete and IO Error dialogs now use QMessageBox. [ Previous: Preparing to Migrate the User Interface ] [ Home ] [ Next: Using Custom QDialogs ]
|
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le Qt Labs au hasardLe moteur de rendu OpenVGLes Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
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 ! |
Copyright © 2000-2012 - www.developpez.com