|Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions|
We have not quite finished with the migration to Qt, even though our project does not use Motif any more. Qt provides many useful features that we can begin using immediately. Some of the most interesting ones are presented below as a guide for where to start extending your existing projects.
Support for internationalization is very easy with Qt. Using QString instead of char* for storing text gives us support for most of the written languages around the world. Our Page and Options structs look much simpler now.
All functions that use the Page and Options structs need to be updated to use QString properly. Since QString is also an implicitly shared class, we no longer have to do any memory management with our strings. We can remove all occurences of the qstrdup() function, and we never need to use new or delete when done with a string. QString will allocate and delete data when needed.
Here are the MainWindow::fileOpen() and MainWindow::pageChange() functions from mainwindow.ui.h. Notice that the code no longer uses delete or qstrdup() when storing text.
Almost all of the functions in our application are affected by this change. In most cases, we end up removing more code than we are adding. To keep the size of this walkthrough reasonable, we've only shown a small portion of the required changes, since the changes are very similar to those shown above.
Qt provides many input and output classes. We can use these in MainWindow::readDB() and MainWindow::saveDB(). Currently, these functions use functions only found on UNIX machines. Using QFile and QTextStream removes this dependency on UNIX, and we can begin building and testing our application on Microsoft Windows and Apple Mac OS X.
The platform-independent versions of the MainWindow::readDB() and MainWindow::saveDB() functions can be found in the io.cpp file.
Since we used the Qt Designer to design the Main Window widget, we can extend the interface easily. We can use some of the more advanced features of QMainWindow, which includes dockable toolbars. Adding these is simple with the Qt Designer. The final version of our project includes a toolbar, which provides quick access to the Open, Save, Print, New Page and Delete to Trash actions.
The possibilities are endless. An Edit menu, with the common Cut, Copy and Paste actions, could be added in a relatively short period of time. As our project expands to other platforms, we could add menus and dialogs that allow us synchronize todo lists between a normal desktop computer and a handheld device running with Qt/Embedded.
[ Previous: Replacing the Print Dialog ] [ Home ]