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();
} |
The program creates a
QApplication object and an
instance of our MulticlipForm, sets the form to be the main widget and
shows the form. The
app.exec() call starts off the
event loop.
We need to add main.cpp to the
.pro file. Open multiclip.pro
in a plain text editor (notepad, vim or 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 |
Add a new line at the end of the file:
If you are using MS Windows and are using Qt as a
DLL
you must add this line at the end of your project files:
Save the updated project file. Now start up a console (or xterm), change
directory to the multiclip application and run
qmake. A Makefile
compatible with your system will be generated:
qmake -o Makefile multiclip.pro |
You can now make the application, e.g. by running
make or
nmake.
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.