So far we have written about 99% of a Qt application entirely in Qt Designer. To make the application compile and run we must create a main.cpp file from which we can call our form. We'll then need to update the project file accordingly and generate a Makefile. We can use the Makefile to generate the application. We will cover these matters briefly here, and in more detail in the section called Subclassing in Chapter 4 "Subclassing".
First we need to create a main.cpp file.
#include <qapplication.h> #include "multiclip.h" int main( int argc, char *argv[] ) { QApplication app( argc, argv ); MulticlipForm clippingForm; app.setMainWidget( &clippingForm ); clippingForm.show(); return app.exec(); } |
We need to add main.cpp to the .pro file. Open multiclip.pro in a plain text editor (such as notepad, vim, xemacs, etc.). It will look similar to this:
TEMPLATE = app CONFIG += qt warn_on release TARGET = multiclip INTERFACES = multiclip.ui IMAGEFILE = images.cpp PROJECTNAME = multiclip LANGUAGE = C++ SOURCES += images.cpp |
SOURCES += main.cpp |
qmake -o Makefile multiclip.pro |
This chapter has introduced you to creating cross-platform applications with Qt Designer. We've created a form, populated it with widgets and laid the widgets out neatly and scalably. We've used Qt's signals and slots mechanism to make the application functional and generated the Makefile. These techniques for adding widgets to a form and laying them out with the layout tools; and for creating, coding and connecting slots will be used time and again as you create applications with Qt Designer. The following chapters will present further examples and explore more techniques for using Qt Designer.