Putting It All Together

Now that we have the code for our dialog, all we need is some test code to try it. The following code is about the simplest piece you can have:

#include <qapplication.h>
#include "PizzaEntry.h"

int main( int argc, char* argv[] )
{
  QApplication app( argc, argv );

  PizzaEntry pizzaEntry;
  app.setMainWidget( &pizzaEntry );
  pizzaEntry.show();

  int ret = app.exec();
  return ret;
}

Save this as PizzaEntryTest.cpp. Now you can start building your program. On a Unix system with the g++ compiler, these could be your command lines:

moc -o moc_PizzaEntry.cpp PizzaEntry.h
g++ -I$QTDIR/include PizzaEntry.cpp PizzaEntryTest.cpp \
moc_PizzaEntry.cpp -L$QTDIR/lib -lqt

and on a Windows system with the Microsoft Visual C++ compiler:

moc -o moc_PizzaEntry.cpp PizzaEntry.h
cl -c -nologo -I%QTDIR%/include -FoPizzaEntry.obj PizzaEntry.cpp
cl -c -nologo -I%QTDIR%/include -FoPizzaEntryTest.obj PizzaEntryTest.cpp
cl -c -nologo -I%QTDIR%/include -Fomoc_PizzaEntry.obj moc_PizzaEntry.cpp
link /NOLOGO /SUBSYSTEM:windows /OUT:PizzaEntry PizzaEntry.obj PizzaEntryTest.obj \
    moc_PizzaEntry.obj %QTDIR%/lib/qt.lib kernel32.lib user32.lib gdi32.lib \
    comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
    imm32.lib winmm.lib wsock32.lib

If you use a different compiler, you might have to change the compiler command and some of the options. If you do not know what the line starting with moc is for, please see the Qt Tutorial or Programming with Qt.

Finally, you can run your program. Figure 2-13 shows the result.

Figure 2-13. Our first program in action