|  | Home · Overviews · Examples

# QCoreApplication Class Reference
[com.trolltech.qt.core module]

The QCoreApplication class provides an event loop for console Qt applications. More...

Inherits `QObject`.

Inherited by `QApplication`.

## Detailed Description

The QCoreApplication class provides an event loop for console Qt applications.

This class is used by non-GUI applications to provide their event loop. For non-GUI application that uses Qt, there should be exactly one QCoreApplication object. For GUI applications, see `QApplication`.

QCoreApplication contains the main event loop, where all events from the operating system (e.g., timer and network events) and other sources are processed and dispatched. It also handles the application's initialization and finalization, as well as system-wide and application-wide settings.

The command line arguments which QCoreApplication's constructor should be called with are accessible using `arguments`. The event loop is started with a call to `exec`. Long running operations can call `processEvents` to keep the application responsive.

Some Qt classes, such as `QString`, can be used without a QCoreApplication object. However, in general, we recommend that you create a QCoreApplication or a `QApplication` object in your `main()` function as early as possible. The application will enter the event loop when `exec` is called. `exit` will not return until the event loop exits, e.g., when `quit` is called.

An application has an `applicationDirPath` and an `applicationFilePath`. Translation files can be added or removed using `installTranslator` and `removeTranslator`. Application strings can be translated using translate(). The QObject::tr() and QObject::trUtf8() functions are implemented in terms of translate().

The class provides a `quit` slot and an `aboutToQuit` signal.

Several static convenience functions are also provided. The QCoreApplication object is available from `instance`. Events can be sent or posted using `sendEvent`, `postEvent`, and `sendPostedEvents`. Pending events can be removed with `removePostedEvents` or flushed with `flush`. Library paths (see QLibrary) can be retrieved with `libraryPaths` and manipulated by `setLibraryPaths`, `addLibraryPath`, and `removeLibraryPath`.

See also `QApplication`, `QAbstractEventDispatcher`, `QEventLoop`, Semaphores Example, and Wait Conditions Example.