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

Using TQt Standard Dialogs

[ Previous: Preparing to Migrate the User Interface ] [ Home ] [ Next: Using Custom TQDialogs ]

We start by using two of the TQt Standard Dialogs: TQFileDialog and TQMessageBox. Both of these classes provide useful static convenience functions.

TQFileDialog::getOpenFileName() replacement for the Open dialog
TQFileDialog::getSaveFileName() replacement for the Save As dialog
TQMessageBox::information() replacement for Page Delete dialog
TQMessageBox::warning() replacement for IO Error dialog.

Each of these functions takes a TQWidget *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 TQMotifWidget create our XmMainWindow, and we can then use this class as the parent for both Motif dialogs and TQt dialogs.

We need to include the appropriate headers for TQMotifWidget and TQFileDialog 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 TQMotif can do this for us. We also let TQApplication open the connection to the X server. Next, we create a TQMotifWidget, passing xmMainWindowWidgetClass as the widgetclass argument. We can now use the TQMotifWidget::motifWidget() function to access the Motif widget. The shell widget is created automatically by TQMotifWidget. We use XtParent() to access it. The top-level window is now a TQMotifWidget, which means we can use it as the parent for the TQt Standard Dialogs.


Replacing the Open and Save As Dialogs

First, 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 TQFileDialog.

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 TQMotifWidget as the client_data to these functions, since we will be using it as the parent for the TQFileDialog.


    ...


Next, we modify the Save() function to use TQFileDialog::getSaveFileName().


... and the Open() function to use TQFileDialog::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 TQFileDialog.

Replacing the Page Delete and IO Error Dialogs

The 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 retquired 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 TQMessageBox::information().

First, we need to make sure we include the proper header for TQMessageBox.


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 TQMotifWidget 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 retquired 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 TQMessageBox::warning().

First, we need to make sure we include the proper header for TQMessageBox.


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 TQMessageBox.

[ Previous: Preparing to Migrate the User Interface ] [ Home ] [ Next: Using Custom TQDialogs ]


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8