QApplication Class Reference


The QApplication class manages the application event queue. (details) (complete member list)

#include <qapp.h>

Public Members

Static Public Members


Detailed Description

The QApplication class manages the application event queue.

The QApplication class is central to Qt. It receives events from the underlying window system and sends them to the destination widgets. An application object must be created before any widgets can be created!

Only one single QApplication object should be created, and this is normally done in the main() function. When a QApplication object has been created, qApp (defined as extern QApplication *qApp) will refer to this object.

Here is a complete Qt application:

#include <qapp.h>
#include <qpushbt.h>

int main( int argc, char **argv )
{
    QApplication a( argc, argv );       // create app object
    QPushButton  hi( "Hello, world" );  // create main widget
    hi.show();                          // show widget
    return a.exec( &hi );               // main event loop
}

Notice that the QApplication object must be created before the widget is defined!.


Member Function Documentation

QApplication::QApplication (int &argc, char **argv)

Creates an application object with the command line parameters argc and argv. The qApp will be set to point to this application object.

Only one application object should be created. This application object must be constructed before any paint devices (includes widgets, pixmaps, bitmaps etc.)

The UNIX/X-Windows version of Qt recognizes these command line options:

QApplication::~QApplication ()

Closes all widgets and cleans up all window system resources. Sets qApp to 0.

bool QApplication::closingDown ()

Returns TRUE if the application objects is being destroyed.

QCursor * QApplication::cursor ()

Returns the application cursor. This function returns 0 if no application cursor has been defined.

See also: setCursor().

QWidget * QApplication::desktop ()

Returns the desktop widget (also called root window).

The desktop widget is useful for obtaining the size of the screen. It can also be used to draw on the desktop.

QWidget *d = QApplication::desktop();
d->height();                    // height of display
d->width();                     // width of display
d->setBackgroundColor( red );

int QApplication::enter_loop ()

This function enters the main event loop (recursively). Do not call it unless you are an expert.

See also: exit_loop().

int QApplication::exec (QWidget *mainWidget)

Enters the main event loop and waits until quit() is called or mainWidget is destroyed. Returns the value that was specified to quit().

If mainWidget is a null pointer, exec will return only when quit() is called. This is for intended for applications that do not want to quit just because the first window was closed.

As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widget have a local event loop. All programs must call exec() to activate other types of widgets.

void QApplication::exit_loop ()

This function leaves from a recursive call to the main event loop. Do not call it unless you are an expert.

See also: enter_loop().

void QApplication::flushX ()

Flushes the X event queue in the X-Windows implementation. Does nothing on other platforms.

QFont * QApplication::font ()

Returns the default application font. There will always be an application font.

See also: setFont().

QWidget * QApplication::mainWidget () const

Returns the widget that was specified to exec().

bool QApplication::notify (QObject *receiver, QEvent *event)

Sends event to receiver: receiver->event( event ); Returns the value that was returned from the event handler.

All Qt events are sent using the notify function. Since this function is virtual, you can make a subclass of QApplication and reimplement notify() to get total control of Qt events.

See also: QObject::event().

QPalette * QApplication::palette ()

Returns a pointer to the default application palette. There will always be an application palette.

void QApplication::postEvent (QObject *receiver, QEvent *event)

Stores the event in a queue and returns immediatly.

Back in the main event loop, all events that are stored in the queue will be sent using the notify() function.

See also: sendEvent().

void QApplication::quit (int retcode)

Tells the application to quit.

After quit has been called, the application leaves the main event loop an returns from the call to exec(). The exec() function returns retcode.

See also: exec().

void QApplication::restoreCursor ()

Restores after some application cursor was set.

See also: setCursor().

bool QApplication::sendEvent (QObject *receiver, QEvent *event)

Sends an event directly to a receiver, using the notify() function. Returns the value that was returned from the event handler.

See also: postEvent().

void QApplication::setCursor (const QCursor &c)

Sets the application cursor to c.

This cursor will be displayed in all application widgets until restoreCursor() is called.

Example of use:

QApplication::setCursor( hourGlassCursor );
calculate_mandelbrot();         // this takes time...
QApplication::restoreCursor();

See also: cursor(), restoreCursor().

void QApplication::setFont (const QFont &f, bool updateAllWidgets=FALSE)

Changes the default application font to f.

If updateAllWidgets is TRUE, then this font will be set for all existing widgets. If updateAllWidgets is FALSE (default), then only widgets created after this call will have this font.

void QApplication::setPalette (const QPalette &p, bool updateAllWidgets=FALSE)

Changes the default application palette to p.

If updateAllWidgets is TRUE, then this palette will be set for all existing widgets. If updateAllWidgets is FALSE (default), then only widgets that are created after this call will have the palette.

void QApplication::setStyle (GUIStyle s)

Sets the application GUI style to s.

The style parameter can be MacStyle, WindowsStyle, PMStyle or MotifStyle. Only MotifStyle is fully supported in the current version of Qt.

See also: style().

bool QApplication::startingUp ()

Returns TRUE if an application object has not been created yet.

GUIStyle QApplication::style ()

Returns the GUI style of the application.

See also: setStyle().

void QApplication::syncX ()

Synchronizes with the X server in the X-Windows implementation. Does nothing on other platforms.


This file is part of the Qt toolkit, copyright 1995 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 16:17, 1995/06/30 by the webmaster at Troll Tech