| Classes | Functions | DevRef | Qt API | Qtopia Documentation |

## Qtopia - The main() function

The `main()` function of all applications should be modelled on this example:

    int main( int argc, char **argv )
    {
        QPEApplication a( argc, argv );

        Main m;
        a.showMainWidget(&m);

        a.exec();
    }

If the application is document-oriented, the call to QPEApplication::showMainWidget() should be replaced by a call to QPEApplication::showMainDocumentWidget().

The application window should be implemented in a self-contained way: it should not perform application-level operations such as testing parameters, calling exit(), or calling quit(); all of these are handled by QPEApplication. Your application window should call close() if it needs to explicitly close, and it must be prepared for the possibility that show() will be called again after the close() but before the application window destructor. In other words, implement your application window in a way that it could be used easily from other applications. If you take this approach it will also mean that most of your program can be trivially reused on Qt/X11, Qt/Windows, Qt/Mac, and any other ports of the Qt API.