Eneboo - Documentación para desarrolladores
Tipos públicos | Slots públicos | Señales | Métodos públicos | Métodos públicos estáticos | Métodos protegidos | Amigas | Funciones relacionadas
Referencia de la Clase QApplication

The QApplication class manages the GUI application's control flow and main settings. Más...

#include <qapplication.h>

Diagrama de herencias de QApplication
QObject QObject Qt Qt Qt Qt DesignerApplication

Lista de todos los miembros.

Tipos públicos

enum  Type {
  Tty, GuiClient, GuiServer, Tty,
  GuiClient, GuiServer
}
enum  ColorMode { NormalColors, CustomColors, NormalColors, CustomColors }
enum  ColorSpec {
  NormalColor = 0, CustomColor = 1, ManyColor = 2, NormalColor = 0,
  CustomColor = 1, ManyColor = 2
}
enum  Encoding { DefaultCodec, UnicodeUTF8, DefaultCodec, UnicodeUTF8 }
enum  Type {
  Tty, GuiClient, GuiServer, Tty,
  GuiClient, GuiServer
}
enum  ColorMode { NormalColors, CustomColors, NormalColors, CustomColors }
enum  ColorSpec {
  NormalColor = 0, CustomColor = 1, ManyColor = 2, NormalColor = 0,
  CustomColor = 1, ManyColor = 2
}
enum  Encoding { DefaultCodec, UnicodeUTF8, DefaultCodec, UnicodeUTF8 }

Slots públicos

void quit ()
void closeAllWindows ()
void aboutQt ()
void quit ()
void closeAllWindows ()
void aboutQt ()

Señales

void lastWindowClosed ()
void aboutToQuit ()
void guiThreadAwake ()
void lastWindowClosed ()
void aboutToQuit ()
void guiThreadAwake ()

Métodos públicos

 QApplication (int &argc, char **argv)
 QApplication (int &argc, char **argv, bool GUIenabled)
 QApplication (int &argc, char **argv, Type)
virtual ~QApplication ()
int argc () const
char ** argv () const
Type type () const
QWidgetmainWidget () const
virtual void setMainWidget (QWidget *)
virtual void polish (QWidget *)
QWidgetfocusWidget () const
QWidgetactiveWindow () const
int exec ()
void processEvents ()
void processEvents (int maxtime)
void processOneEvent ()
bool hasPendingEvents ()
int enter_loop ()
void exit_loop ()
int loopLevel () const
virtual bool notify (QObject *, QEvent *)
void setDefaultCodec (QTextCodec *)
QTextCodecdefaultCodec () const
void installTranslator (QTranslator *)
void removeTranslator (QTranslator *)
virtual QString translate (const char *context, const char *key, const char *comment=0, Encoding encoding=DefaultCodec) const
QString applicationDirPath ()
QString applicationFilePath ()
bool isSessionRestored () const
QString sessionId () const
QString sessionKey () const
virtual void commitData (QSessionManager &sm)
virtual void saveState (QSessionManager &sm)
void wakeUpGuiThread ()
 QApplication (int &argc, char **argv)
 QApplication (int &argc, char **argv, bool GUIenabled)
 QApplication (int &argc, char **argv, Type)
virtual ~QApplication ()
int argc () const
char ** argv () const
Type type () const
QWidgetmainWidget () const
virtual void setMainWidget (QWidget *)
virtual void polish (QWidget *)
QWidgetfocusWidget () const
QWidgetactiveWindow () const
int exec ()
void processEvents ()
void processEvents (int maxtime)
void processOneEvent ()
bool hasPendingEvents ()
int enter_loop ()
void exit_loop ()
int loopLevel () const
virtual bool notify (QObject *, QEvent *)
void setDefaultCodec (QTextCodec *)
QTextCodecdefaultCodec () const
void installTranslator (QTranslator *)
void removeTranslator (QTranslator *)
virtual QString translate (const char *context, const char *key, const char *comment=0, Encoding encoding=DefaultCodec) const
QString applicationDirPath ()
QString applicationFilePath ()
bool isSessionRestored () const
QString sessionId () const
QString sessionKey () const
virtual void commitData (QSessionManager &sm)
virtual void saveState (QSessionManager &sm)
void wakeUpGuiThread ()

Métodos públicos estáticos

static QStylestyle ()
static void setStyle (QStyle *)
static QStylesetStyle (const QString &)
static ColorMode colorMode ()
static void setColorMode (QApplication::ColorMode)
static int colorSpec ()
static void setColorSpec (int)
static QCursoroverrideCursor ()
static void setOverrideCursor (const QCursor &, bool replace=FALSE)
static void restoreOverrideCursor ()
static bool hasGlobalMouseTracking ()
static void setGlobalMouseTracking (bool enable)
static QPalette palette (const QWidget *=0)
static void setPalette (const QPalette &, bool informWidgets=FALSE, const char *className=0)
static QFont font (const QWidget *=0)
static void setFont (const QFont &, bool informWidgets=FALSE, const char *className=0)
static QFontMetrics fontMetrics ()
static QWidgetListallWidgets ()
static QWidgetListtopLevelWidgets ()
static QDesktopWidgetdesktop ()
static QWidgetactivePopupWidget ()
static QWidgetactiveModalWidget ()
static QClipboardclipboard ()
static QWidgetwidgetAt (int x, int y, bool child=FALSE)
static QWidgetwidgetAt (const QPoint &, bool child=FALSE)
static QEventLoopeventLoop ()
static void exit (int retcode=0)
static bool sendEvent (QObject *receiver, QEvent *event)
static void postEvent (QObject *receiver, QEvent *event)
static void sendPostedEvents (QObject *receiver, int event_type)
static void sendPostedEvents ()
static void removePostedEvents (QObject *receiver)
static bool startingUp ()
static bool closingDown ()
static void flushX ()
static void flush ()
static void syncX ()
static void beep ()
static void setWinStyleHighlightColor (const QColor &c)
static const QColorwinStyleHighlightColor ()
static void setDesktopSettingsAware (bool)
static bool desktopSettingsAware ()
static void setCursorFlashTime (int)
static int cursorFlashTime ()
static void setDoubleClickInterval (int)
static int doubleClickInterval ()
static void setWheelScrollLines (int)
static int wheelScrollLines ()
static void setGlobalStrut (const QSize &)
static QSize globalStrut ()
static void setLibraryPaths (const QStringList &)
static QStringList libraryPaths ()
static void addLibraryPath (const QString &)
static void removeLibraryPath (const QString &)
static void setStartDragTime (int ms)
static int startDragTime ()
static void setStartDragDistance (int l)
static int startDragDistance ()
static void setReverseLayout (bool b)
static bool reverseLayout ()
static int horizontalAlignment (int align)
static bool isEffectEnabled (Qt::UIEffect)
static void setEffectEnabled (Qt::UIEffect, bool enable=TRUE)
static QStylestyle ()
static void setStyle (QStyle *)
static QStylesetStyle (const QString &)
static ColorMode colorMode ()
static void setColorMode (QApplication::ColorMode)
static int colorSpec ()
static void setColorSpec (int)
static QCursoroverrideCursor ()
static void setOverrideCursor (const QCursor &, bool replace=FALSE)
static void restoreOverrideCursor ()
static bool hasGlobalMouseTracking ()
static void setGlobalMouseTracking (bool enable)
static QPalette palette (const QWidget *=0)
static void setPalette (const QPalette &, bool informWidgets=FALSE, const char *className=0)
static QFont font (const QWidget *=0)
static void setFont (const QFont &, bool informWidgets=FALSE, const char *className=0)
static QFontMetrics fontMetrics ()
static QWidgetListallWidgets ()
static QWidgetListtopLevelWidgets ()
static QDesktopWidgetdesktop ()
static QWidgetactivePopupWidget ()
static QWidgetactiveModalWidget ()
static QClipboardclipboard ()
static QWidgetwidgetAt (int x, int y, bool child=FALSE)
static QWidgetwidgetAt (const QPoint &, bool child=FALSE)
static QEventLoopeventLoop ()
static void exit (int retcode=0)
static bool sendEvent (QObject *receiver, QEvent *event)
static void postEvent (QObject *receiver, QEvent *event)
static void sendPostedEvents (QObject *receiver, int event_type)
static void sendPostedEvents ()
static void removePostedEvents (QObject *receiver)
static bool startingUp ()
static bool closingDown ()
static void flushX ()
static void flush ()
static void syncX ()
static void beep ()
static void setWinStyleHighlightColor (const QColor &c)
static const QColorwinStyleHighlightColor ()
static void setDesktopSettingsAware (bool)
static bool desktopSettingsAware ()
static void setCursorFlashTime (int)
static int cursorFlashTime ()
static void setDoubleClickInterval (int)
static int doubleClickInterval ()
static void setWheelScrollLines (int)
static int wheelScrollLines ()
static void setGlobalStrut (const QSize &)
static QSize globalStrut ()
static void setLibraryPaths (const QStringList &)
static QStringList libraryPaths ()
static void addLibraryPath (const QString &)
static void removeLibraryPath (const QString &)
static void setStartDragTime (int ms)
static int startDragTime ()
static void setStartDragDistance (int l)
static int startDragDistance ()
static void setReverseLayout (bool b)
static bool reverseLayout ()
static int horizontalAlignment (int align)
static bool isEffectEnabled (Qt::UIEffect)
static void setEffectEnabled (Qt::UIEffect, bool enable=TRUE)

Métodos protegidos

bool event (QEvent *)
bool event (QEvent *)

Amigas

class FLApplication
class QWidget
class QETWidget
class QDialog
class QAccelManager
class QEvent
class QTranslator
class QEventLoop
Q_EXPORT void qt_ucm_initialize (QApplication *)
Q_EXPORT void qt_ucm_initialize (QApplication *)

Funciones relacionadas

(Observar que estas no son funciones miembro.)

Q_EXPORT void qAddPostRoutine (QtCleanUpFunction p)
const char * qVersion ()
bool qSysInfo (int *wordSize, bool *bigEndian)
void qDebug (const char *msg,...)
void qWarning (const char *msg,...)
void qFatal (const char *msg,...)
void qSystemWarning (const char *msg, int code)
void Q_ASSERT (bool test)
void Q_CHECK_PTR (void *p)
QtMsgHandler qInstallMsgHandler (QtMsgHandler h)

Descripción detallada

The QApplication class manages the GUI application's control flow and main settings.

It contains the main event loop, where all events from the window system and other sources are processed and dispatched. It also handles the application's initialization and finalization, and provides session management. It also handles most system-wide and application-wide settings.

For any GUI application that uses Qt, there is precisely one QApplication object, no matter whether the application has 0, 1, 2 or more windows at any time.

The QApplication object is accessible through the global pointer qApp. Its main areas of responsibility are:

It initializes the application with the user's desktop settings such as palette(), font() and doubleClickInterval(). It keeps track of these properties in case the user changes the desktop globally, for example through some kind of control panel.

It performs event handling, meaning that it receives events from the underlying window system and dispatches them to the relevant widgets. By using sendEvent() and postEvent() you can send your own events to widgets.

It parses common command line arguments and sets its internal state accordingly. See the constructor documentation below for more details about this.

It defines the application's look and feel, which is encapsulated in a QStyle object. This can be changed at runtime with setStyle().

It specifies how the application is to allocate colors. See setColorSpec() for details.

It provides localization of strings that are visible to the user via translate().

It provides some magical objects like the desktop() and the clipboard().

It knows about the application's windows. You can ask which widget is at a certain position using widgetAt(), get a list of topLevelWidgets() and closeAllWindows(), etc.

It manages the application's mouse cursor handling, see setOverrideCursor() and setGlobalMouseTracking().

On the X window system, it provides functions to flush and sync the communication stream, see flushX() and syncX().

It provides support for sophisticated session management . This makes it possible for applications to terminate gracefully when the user logs out, to cancel a shutdown process if termination isn't possible and even to preserve the entire application's state for a future session. See isSessionRestored(), sessionId() and commitData() and saveState() for details.

The Application walk-through example contains a typical complete main() that does the usual things with QApplication.

Since the QApplication object does so much initialization, it must be created before any other objects related to the user interface are created.

Since it also deals with common command line arguments, it is usually a good idea to create it before any interpretation or modification of argv is done in the application itself. (Note also that for X11, setMainWidget() may change the main widget according to the -geometry option. To preserve this functionality, you must set your defaults before setMainWidget() and any overrides after.)

Groups of functions System settings desktopSettingsAware(), setDesktopSettingsAware(), cursorFlashTime(), setCursorFlashTime(), doubleClickInterval(), setDoubleClickInterval(), wheelScrollLines(), setWheelScrollLines(), palette(), setPalette(), font(), setFont(), fontMetrics().

Event handling exec(), processEvents(), enter_loop(), exit_loop(), exit(), quit(). sendEvent(), postEvent(), sendPostedEvents(), removePostedEvents(), hasPendingEvents(), notify(), macEventFilter(), qwsEventFilter(), x11EventFilter(), x11ProcessEvent(), winEventFilter().

GUI Styles style(), setStyle(), polish().

Color usage colorSpec(), setColorSpec(), qwsSetCustomColors().

Text handling installTranslator(), removeTranslator() translate().

Widgets mainWidget(), setMainWidget(), allWidgets(), topLevelWidgets(), desktop(), activePopupWidget(), activeModalWidget(), clipboard(), focusWidget(), winFocus(), activeWindow(), widgetAt().

Advanced cursor handling hasGlobalMouseTracking(), setGlobalMouseTracking(), overrideCursor(), setOverrideCursor(), restoreOverrideCursor().

X Window System synchronization flushX(), syncX().

Session management isSessionRestored(), sessionId(), commitData(), saveState().

Threading lock(), unlock(), locked(), tryLock(), wakeUpGuiThread()

Miscellaneous closeAllWindows(), startingUp(), closingDown(), type().

{Non-GUI programs:} While Qt is not optimized or designed for writing non-GUI programs, it's possible to use some of its classes without creating a QApplication. This can be useful if you wish to share code between a non-GUI server and a GUI client.


Documentación de las enumeraciones miembro de la clase

Valores de enumeraciones:
NormalColors 
CustomColors 
NormalColors 
CustomColors 
Valores de enumeraciones:
NormalColors 
CustomColors 
NormalColors 
CustomColors 
Valores de enumeraciones:
NormalColor 
CustomColor 
ManyColor 
NormalColor 
CustomColor 
ManyColor 

NormalColor the default color allocation policy CustomColor the same as NormalColor for X11; allocates colors to a palette on demand under Windows ManyColor the right choice for applications that use thousands of colors

See setColorSpec() for full details.

Valores de enumeraciones:
NormalColor 
CustomColor 
ManyColor 
NormalColor 
CustomColor 
ManyColor 

This enum type defines the 8-bit encoding of character string arguments to translate():

DefaultCodec - the encoding specified by QTextCodec::codecForTr() (Latin-1 if none has been set) UnicodeUTF8 - UTF-8

Ver también:
QObject::tr(), QObject::trUtf8(), QString::fromUtf8()
Valores de enumeraciones:
DefaultCodec 
UnicodeUTF8 
DefaultCodec 
UnicodeUTF8 
Valores de enumeraciones:
DefaultCodec 
UnicodeUTF8 
DefaultCodec 
UnicodeUTF8 

Tty a console application GuiClient a GUI client application GuiServer a GUI server application

Valores de enumeraciones:
Tty 
GuiClient 
GuiServer 
Tty 
GuiClient 
GuiServer 
Valores de enumeraciones:
Tty 
GuiClient 
GuiServer 
Tty 
GuiClient 
GuiServer 

Documentación del constructor y destructor

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

Initializes the window system and constructs an application object with argc command line arguments in argv.

The global qApp pointer refers to this application object. Only one application object should be created.

This application object must be constructed before any paint devices (including widgets, pixmaps, bitmaps etc.).

Note that argc and argv might be changed. Qt removes command line arguments that it recognizes. The modified argc and argv can also be accessed later with qApp->argc() and qApp->argv(). The documentation for argv() contains a detailed description of how to process command line arguments.

Qt debugging options (not available if Qt was compiled with the QT_NO_DEBUG flag defined): -nograb, tells Qt that it must never grab the mouse or the keyboard. -dograb (only under X11), running under a debugger can cause an implicit -nograb, use -dograb to override. -sync (only under X11), switches to synchronous mode for debugging.

See Debugging Techniques for a more detailed explanation.

All Qt programs automatically support the following command line options: -reverse causes text to be formatted for right-to-left languages rather than in the usual left-to-right direction. -style= style, sets the application GUI style. Possible values are motif, windows, and platinum. If you compiled Qt with additional styles or have additional styles as plugins these will be available to the -style command line option. -style style, is the same as listed above. -session= session, restores the application from an earlier session . -session session, is the same as listed above. -widgetcount, prints debug message at the end about number of widgets left undestroyed and maximum number of widgets existed at the same time

The X11 version of Qt also supports some traditional X11 command line options: -display display, sets the X display (default is $DISPLAY). -geometry geometry, sets the client geometry of the main widget. -fn or -font font, defines the application font. The font should be specified using an X logical font description. -bg or -background color, sets the default background color and an application palette (light and dark shades are calculated). -fg or -foreground color, sets the default foreground color. -btn or -button color, sets the default button color. -name name, sets the application name. -title title, sets the application title (caption). -visual TrueColor, forces the application to use a TrueColor visual on an 8-bit display. -ncols count, limits the number of colors allocated in the color cube on an 8-bit display, if the application is using the QApplication::ManyColor color specification. If count is 216 then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green, and 6 of blue); for other values, a cube approximately proportional to a 2x3x1 cube is used. -cmap, causes the application to install a private color map on an 8-bit display.

Ver también:
argc(), argv()
QApplication::QApplication ( int argc,
char **  argv,
bool  GUIenabled 
)

Constructs an application object with argc command line arguments in argv. If GUIenabled is TRUE, a GUI application is constructed, otherwise a non-GUI (console) application is created.

Set GUIenabled to FALSE for programs without a graphical user interface that should be able to run without a window system.

On X11, the window system is initialized if GUIenabled is TRUE. If GUIenabled is FALSE, the application does not connect to the X-server. On Windows and Macintosh, currently the window system is always initialized, regardless of the value of GUIenabled. This may change in future versions of Qt.

The following example shows how to create an application that uses a graphical interface when available.

  int main( int argc, char **argv )
  {
#ifdef Q_WS_X11
    bool useGUI = getenv( "DISPLAY" ) != 0;
#else
    bool useGUI = TRUE;
#endif
    QApplication app(argc, argv, useGUI);

    if ( useGUI ) {
       //start GUI version
       ...
    } else {
       //start non-GUI version
       ...
    }
    return app.exec();
  }
QApplication::QApplication ( int argc,
char **  argv,
Type  type 
)

Constructs an application object with argc command line arguments in argv.

For Qt/Embedded, passing QApplication::GuiServer for type makes this application the server (equivalent to running with the -qws option).

QApplication::~QApplication ( ) [virtual]

Cleans up any window system resources that were allocated by this application. Sets the global variable qApp to 0.

QApplication::QApplication ( int argc,
char **  argv 
)
QApplication::QApplication ( int argc,
char **  argv,
bool  GUIenabled 
)
QApplication::QApplication ( int argc,
char **  argv,
Type   
)
virtual QApplication::~QApplication ( ) [virtual]

Documentación de las funciones miembro

void QApplication::aboutQt ( ) [slot]

Displays a simple message box about Qt. The message includes the version number of Qt being used by the application.

This is useful for inclusion in the Help menu of an application. See the examples/menu/menu.cpp example.

This function is a convenience slot for QMessageBox::aboutQt().

void QApplication::aboutQt ( ) [slot]
void QApplication::aboutToQuit ( ) [signal]

This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session.

The signal is particularly useful if your application has to do some last-second cleanup. Note that no user interaction is possible in this state.

Ver también:
quit()
void QApplication::aboutToQuit ( ) [signal]
QWidget * QApplication::activeModalWidget ( ) [static]

Returns the active modal widget.

A modal widget is a special top level widget which is a subclass of QDialog that specifies the modal parameter of the constructor as TRUE. A modal widget must be closed before the user can continue with other parts of the program.

Modal widgets are organized in a stack. This function returns the active modal widget at the top of the stack.

Ver también:
activePopupWidget(), topLevelWidgets()
static QWidget* QApplication::activeModalWidget ( ) [static]
QWidget * QApplication::activePopupWidget ( ) [static]

Returns the active popup widget.

A popup widget is a special top level widget that sets the WType_Popup widget flag, e.g. the QPopupMenu widget. When the application opens a popup widget, all events are sent to the popup. Normal widgets and modal widgets cannot be accessed before the popup widget is closed.

Only other popup widgets may be opened when a popup widget is shown. The popup widgets are organized in a stack. This function returns the active popup widget at the top of the stack.

Ver también:
activeModalWidget(), topLevelWidgets()
static QWidget* QApplication::activePopupWidget ( ) [static]
QWidget* QApplication::activeWindow ( ) const
QWidget * QApplication::activeWindow ( ) const [inline]

Returns the application top-level window that has the keyboard input focus, or 0 if no application window has the focus. Note that there might be an activeWindow() even if there is no focusWidget(), for example if no widget in that window accepts key events.

Ver también:
QWidget::setFocus(), QWidget::hasFocus(), focusWidget()
void QApplication::addLibraryPath ( const QString path) [static]

Append path to the end of the library path list. If path is empty or already in the path list, the path list is not changed.

The default path list consists of a single entry, the installation directory for plugins. The default installation directory for plugins is INSTALL/plugins, where INSTALL is the directory where Qt was installed.

Ver también:
removeLibraryPath(), libraryPaths(), setLibraryPaths()
static void QApplication::addLibraryPath ( const QString ) [static]
QWidgetList * QApplication::allWidgets ( ) [static]

Returns a list of all the widgets in the application.

The list is created using new and must be deleted by the caller.

The list is empty (QPtrList::isEmpty()) if there are no widgets.

Note that some of the widgets may be hidden.

Example that updates all widgets:

    QWidgetList  *list = QApplication::allWidgets();
    QWidgetListIt it( *list );         // iterate over the widgets
    QWidget * w;
    while ( (w=it.current()) != 0 ) {  // for each widget...
  ++it;
  w->update();
    }
    delete list;                      // delete the list, not the widgets

The QWidgetList class is defined in the qwidgetlist.h header file.

Atención:
Delete the list as soon as you have finished using it. The widgets in the list may be deleted by someone else at any time.
Ver también:
topLevelWidgets(), QWidget::isVisible(), QPtrList::isEmpty(),
static QWidgetList* QApplication::allWidgets ( ) [static]
QString QApplication::applicationDirPath ( )
QString QApplication::applicationDirPath ( )

Returns the directory that contains the application executable.

For example, if you have installed Qt in the {C:} directory, and you run the {demo} example, this function will return "C:/Trolltech/Qt/examples/demo".

On Mac OS X this will point to the directory actually containing the executable, which may be inside of an application bundle (if the application is bundled).

Atención:
On Unix, this function assumes that argv[0] contains the file name of the executable (which it normally does). It also assumes that the current directory hasn't been changed by the application.
Ver también:
applicationFilePath()
QString QApplication::applicationFilePath ( )
QString QApplication::applicationFilePath ( )

Returns the file path of the application executable.

For example, if you have installed Qt in the {C:} directory, and you run the {demo} example, this function will return "C:/Trolltech/Qt/examples/demo/demo.exe".

Atención:
On Unix, this function assumes that argv[0] contains the file name of the executable (which it normally does). It also assumes that the current directory hasn't been changed by the application.
Ver también:
applicationDirPath()
int QApplication::argc ( ) const [inline]

Returns the number of command line arguments.

The documentation for argv() describes how to process command line arguments.

Ver también:
argv(), QApplication::QApplication()
int QApplication::argc ( ) const
char ** QApplication::argv ( ) const [inline]

Returns the command line argument vector.

argv()[0] is the program name, argv()[1] is the first argument and argv()[argc()-1] is the last argument.

A QApplication object is constructed by passing argc and argv from the main() function. Some of the arguments may be recognized as Qt options and removed from the argument vector. For example, the X11 version of Qt knows about -display, -font and a few more options.

Example:

  // showargs.cpp - displays program arguments in a list box

  #include <qapplication.h>
  #include <qlistbox.h>

  int main( int argc, char **argv )
  {
      QApplication a( argc, argv );
      QListBox b;
      a.setMainWidget( &b );
      for ( int i = 0; i < a.argc(); i++ )  // a.argc() == argc
    b.insertItem( a.argv()[i] );      // a.argv()[i] == argv[i]
      b.show();
      return a.exec();
  }

If you run {showargs -display unix:0 -font 9x15bold hello world} under X11, the list box contains the three strings "showargs", "hello" and "world".

Qt provides a global pointer, qApp, that points to the QApplication object, and through which you can access argc() and argv() in functions other than main().

Ver también:
argc(), QApplication::QApplication()
char** QApplication::argv ( ) const
static void QApplication::beep ( ) [static]
void QApplication::beep ( ) [static]

Sounds the bell, using the default volume and sound.

static QClipboard* QApplication::clipboard ( ) [static]
QClipboard * QApplication::clipboard ( ) [static]

Returns a pointer to the application global clipboard.

void QApplication::closeAllWindows ( ) [slot]

Closes all top-level windows.

This function is particularly useful for applications with many top-level windows. It could, for example, be connected to a "Quit" entry in the file menu as shown in the following code example:

    // the "Quit" menu entry should try to close all windows
    QPopupMenu* file = new QPopupMenu( this );
    file->insertItem( "&Quit", qApp, SLOT(closeAllWindows()), CTRL+Key_Q );

    // when the last window is closed, the application should quit
    connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );

The windows are closed in random order, until one window does not accept the close event.

Ver también:
QWidget::close(), QWidget::closeEvent(), lastWindowClosed(), quit(), topLevelWidgets(), QWidget::isTopLevel()
void QApplication::closeAllWindows ( ) [slot]
static bool QApplication::closingDown ( ) [static]
bool QApplication::closingDown ( ) [static]

Returns TRUE if the application objects are being destroyed; otherwise returns FALSE.

Ver también:
startingUp()
static ColorMode QApplication::colorMode ( ) [static]
QApplication::ColorMode QApplication::colorMode ( ) [static]
int QApplication::colorSpec ( ) [static]

Returns the color specification.

Ver también:
QApplication::setColorSpec()
static int QApplication::colorSpec ( ) [static]
void QApplication::commitData ( QSessionManager sm) [virtual]

This function deals with session management. It is invoked when the QSessionManager wants the application to commit all its data.

Usually this means saving all open files, after getting permission from the user. Furthermore you may want to provide a means by which the user can cancel the shutdown.

Note that you should not exit the application within this function. Instead, the session manager may or may not do this afterwards, depending on the context.

Atención:
Within this function, no user interaction is possible, unless you ask the session manager sm for explicit permission. See QSessionManager::allowsInteraction() and QSessionManager::allowsErrorInteraction() for details and example usage.

The default implementation requests interaction and sends a close event to all visible top level widgets. If any event was rejected, the shutdown is canceled.

Ver también:
isSessionRestored(), sessionId(), saveState(), the Session Management overview
virtual void QApplication::commitData ( QSessionManager sm) [virtual]
int QApplication::cursorFlashTime ( ) [static]

Returns the text cursor's flash time in milliseconds. The flash time is the time required to display, invert and restore the caret display.

The default value on X11 is 1000 milliseconds. On Windows, the control panel value is used.

Widgets should not cache this value since it may vary any time the user changes the global desktop settings.

Ver también:
setCursorFlashTime()

Returns the text cursor's flash (blink) time in milliseconds. The flash time is the time required to display, invert and restore the caret display.

The default value on X11 is 1000 milliseconds. On Windows, the control panel value is used.

Widgets should not cache this value since it may be changed at any time by the user changing the global desktop settings.

Ver también:
setCursorFlashTime()
static int QApplication::cursorFlashTime ( ) [static]
QTextCodec* QApplication::defaultCodec ( ) const
QTextCodec * QApplication::defaultCodec ( ) const
QDesktopWidget * QApplication::desktop ( ) [static]

Returns the desktop widget (also called the root window).

The desktop widget is useful for obtaining the size of the screen. It may also be possible to draw on the desktop. We recommend against assuming that it's possible to draw on the desktop, since this does not work on all operating systems.

    QDesktopWidget *d = QApplication::desktop();
    int w = d->width();     // returns desktop width
    int h = d->height();    // returns desktop height
static QDesktopWidget* QApplication::desktop ( ) [static]
bool QApplication::desktopSettingsAware ( ) [static]

Returns the value set by setDesktopSettingsAware(); by default TRUE.

Ver también:
setDesktopSettingsAware()
static bool QApplication::desktopSettingsAware ( ) [static]
int QApplication::doubleClickInterval ( ) [static]

Returns the maximum duration for a double click.

The default value on X11 is 400 milliseconds. On Windows, the control panel value is used.

Ver también:
setDoubleClickInterval()
static int QApplication::doubleClickInterval ( ) [static]
int QApplication::enter_loop ( )
int QApplication::enter_loop ( )

This function enters the main event loop (recursively). Do not call it unless you really know what you are doing.

Use QApplication::eventLoop()->enterLoop() instead.

bool QApplication::event ( QEvent e) [protected, virtual]

Reimplementado de QObject.

bool QApplication::event ( QEvent e) [protected, virtual]

This virtual function receives events to an object and should return TRUE if the event e was recognized and processed.

The event() function can be reimplemented to customize the behavior of an object.

Ver también:
installEventFilter(), timerEvent(), QApplication::sendEvent(), QApplication::postEvent(), QWidget::event()

Reimplementado de QObject.

QEventLoop * QApplication::eventLoop ( ) [static]

Returns the application event loop. This function will return zero if called during and after destroying QApplication.

To create your own instance of QEventLoop or QEventLoop subclass create it before you create the QApplication object.

Ver también:
QEventLoop
static QEventLoop* QApplication::eventLoop ( ) [static]
int QApplication::exec ( )
int QApplication::exec ( )

Enters the main event loop and waits until exit() is called or the main widget is destroyed, and returns the value that was set to exit() (which is 0 if exit() is called via quit()).

It is necessary to call this function to start event handling. The main event loop receives events from the window system and dispatches these to the application widgets.

Generally speaking, no user interaction can take place before calling exec(). As a special case, modal widgets like QMessageBox can be used before calling exec(), because modal widgets call exec() to start a local event loop.

To make your application perform idle processing, i.e. executing a special function whenever there are no pending events, use a QTimer with 0 timeout. More advanced idle processing schemes can be achieved using processEvents().

Ver también:
quit(), exit(), processEvents(), setMainWidget()
static void QApplication::exit ( int  retcode = 0) [static]
void QApplication::exit ( int  retcode = 0) [static]

Tells the application to exit with a return code.

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

By convention, a retcode of 0 means success, and any non-zero value indicates an error.

Note that unlike the C library function of the same name, this function does return to the caller -- it is event processing that stops.

Ver también:
quit(), exec()
void QApplication::exit_loop ( )
void QApplication::exit_loop ( )

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

Use QApplication::eventLoop()->exitLoop() instead.

static void QApplication::flush ( ) [static]
void QApplication::flush ( ) [static]

Flushes the window system specific event queues.

If you are doing graphical changes inside a loop that does not return to the event loop on asynchronous window systems like X11 or double buffered window systems like MacOS X, and you want to visualize these changes immediately (e.g. Splash Screens), call this function.

Ver también:
flushX() sendPostedEvents() QPainter::flush()
static void QApplication::flushX ( ) [static]
void QApplication::flushX ( ) [static]

Flushes the X event queue in the X11 implementation. This normally returns almost immediately. Does nothing on other platforms.

Ver también:
syncX()
QWidget* QApplication::focusWidget ( ) const
QWidget * QApplication::focusWidget ( ) const [inline]

Returns the application widget that has the keyboard input focus, or 0 if no widget in this application has the focus.

Ver también:
QWidget::setFocus(), QWidget::hasFocus(), activeWindow()
QFont QApplication::font ( const QWidget w = 0) [static]

Returns the default font for the widget w, or the default application font if w is 0.

Ver también:
setFont(), fontMetrics(), QWidget::font()
static QFont QApplication::font ( const QWidget = 0) [static]
QFontMetrics QApplication::fontMetrics ( ) [static]

Returns display (screen) font metrics for the application font.

Ver también:
font(), setFont(), QWidget::fontMetrics(), QPainter::fontMetrics()
static QFontMetrics QApplication::fontMetrics ( ) [static]
QSize QApplication::globalStrut ( ) [inline, static]

Returns the application's global strut.

The strut is a size object whose dimensions are the minimum that any GUI element that the user can interact with should have. For example no button should be resized to be smaller than the global strut size.

Ver también:
setGlobalStrut()
static QSize QApplication::globalStrut ( ) [static]
void QApplication::guiThreadAwake ( ) [signal]
void QApplication::guiThreadAwake ( ) [signal]

This signal is emitted after the event loop returns from a function that could block.

Ver también:
wakeUpGuiThread()
static bool QApplication::hasGlobalMouseTracking ( ) [static]
bool QApplication::hasGlobalMouseTracking ( ) [inline, static]

Returns TRUE if global mouse tracking is enabled, otherwise false.

Ver también:
setGlobalMouseTracking()

Returns TRUE if global mouse tracking is enabled; otherwise returns FALSE.

Ver también:
setGlobalMouseTracking()
bool QApplication::hasPendingEvents ( )
bool QApplication::hasPendingEvents ( )

This function returns TRUE if there are pending events; otherwise returns FALSE. Pending events can be either from the window system or posted events using QApplication::postEvent().

int QApplication::horizontalAlignment ( int  align) [inline, static]

Strips out vertical alignment flags and transforms an alignment align of AlignAuto into AlignLeft or AlignRight according to the language used. The other horizontal alignment flags are left untouched.

static int QApplication::horizontalAlignment ( int  align) [static]
void QApplication::installTranslator ( QTranslator )
void QApplication::installTranslator ( QTranslator mf)

Adds the message file mf to the list of message files to be used for translations.

Multiple message files can be installed. Translations are searched for in the last installed message file, then the one from last, and so on, back to the first installed message file. The search stops as soon as a matching translation is found.

Ver también:
removeTranslator() translate() QTranslator::load()
bool QApplication::isEffectEnabled ( Qt::UIEffect  effect) [static]

Returns TRUE if effect is enabled; otherwise returns FALSE.

By default, Qt will try to use the desktop settings. Call setDesktopSettingsAware(FALSE) to prevent this.

Note: All effects are disabled on screens running at less than 16-bit color depth.

Ver también:
setEffectEnabled(), Qt::UIEffect
static bool QApplication::isEffectEnabled ( Qt::UIEffect  ) [static]
bool QApplication::isSessionRestored ( ) const [inline]

Returns TRUE if the application has been restored from an earlier session; otherwise returns FALSE.

Ver también:
sessionId(), commitData(), saveState()
bool QApplication::isSessionRestored ( ) const
void QApplication::lastWindowClosed ( ) [signal]

This signal is emitted when the user has closed the last top level window.

The signal is very useful when your application has many top level widgets but no main widget. You can then connect it to the quit() slot.

For convenience, this signal is not emitted for transient top level widgets such as popup menus and dialogs.

Ver también:
mainWidget(), topLevelWidgets(), QWidget::isTopLevel(), QWidget::close()
void QApplication::lastWindowClosed ( ) [signal]
QStringList QApplication::libraryPaths ( ) [static]

Returns a list of paths that the application will search when dynamically loading libraries. The installation directory for plugins is the only entry if no paths have been set. The default installation directory for plugins is INSTALL/plugins, where INSTALL is the directory where Qt was installed. The directory of the application executable (NOT the working directory) is also added to the plugin paths.

If you want to iterate over the list, you should iterate over a copy, e.g.

    QStringList list = app.libraryPaths();
    QStringList::Iterator it = list.begin();
    while( it != list.end() ) {
  myProcessing( *it );
  ++it;
    }

See the plugins documentation for a description of how the library paths are used.

Ver también:
setLibraryPaths(), addLibraryPath(), removeLibraryPath(), QLibrary
static QStringList QApplication::libraryPaths ( ) [static]
int QApplication::loopLevel ( ) const
int QApplication::loopLevel ( ) const

Returns the current loop level.

Use QApplication::eventLoop()->loopLevel() instead.

QWidget * QApplication::mainWidget ( ) const [inline]

Returns the main application widget, or 0 if there is no main widget.

Ver también:
setMainWidget()
QWidget* QApplication::mainWidget ( ) const
virtual bool QApplication::notify ( QObject ,
QEvent  
) [virtual]
bool QApplication::notify ( QObject receiver,
QEvent e 
) [virtual]

Sends event e to receiver: {receiver}->event(e). Returns the value that is returned from the receiver's event handler.

For certain types of events (e.g. mouse and key events), the event will be propagated to the receiver's parent and so on up to the top-level object if the receiver is not interested in the event (i.e., it returns FALSE).

There are five different ways that events can be processed; reimplementing this virtual function is just one of them. All five approaches are listed below: 1 Reimplementing this function. This is very powerful, providing complete control; but only one subclass can be qApp.

Installing an event filter on qApp. Such an event filter is able to process all events for all widgets, so it's just as powerful as reimplementing notify(); furthermore, it's possible to have more than one application-global event filter. Global event filters even see mouse events for disabled widgets, and if global mouse tracking is enabled, as well as mouse move events for all widgets.

Reimplementing QObject::event() (as QWidget does). If you do this you get Tab key presses, and you get to see the events before any widget-specific event filters.

Installing an event filter on the object. Such an event filter gets all the events except Tab and Shift-Tab key presses.

Reimplementing paintEvent(), mousePressEvent() and so on. This is the commonest, easiest and least powerful way.

Ver también:
QObject::event(), installEventFilter()
QCursor * QApplication::overrideCursor ( ) [inline, static]

Returns the active application override cursor.

This function returns 0 if no application cursor has been defined (i.e. the internal cursor stack is empty).

Ver también:
setOverrideCursor(), restoreOverrideCursor()
static QCursor* QApplication::overrideCursor ( ) [static]
QPalette QApplication::palette ( const QWidget w = 0) [static]

Returns the application palette.

If a widget is passed in w, the default palette for the widget's class is returned. This may or may not be the application palette. In most cases there isn't a special palette for certain types of widgets, but one notable exception is the popup menu under Windows, if the user has defined a special background color for menus in the display settings.

Ver también:
setPalette(), QWidget::palette()
static QPalette QApplication::palette ( const QWidget = 0) [static]
void QApplication::polish ( QWidget w) [virtual]

Initialization of the appearance of the widget w before it is first shown.

Usually widgets call this automatically when they are polished. It may be used to do some style-based central customization of widgets.

Note that you are not limited to the public functions of QWidget. Instead, based on meta information like QObject::className() you are able to customize any kind of widget.

Ver también:
QStyle::polish(), QWidget::polish(), setPalette(), setFont()
virtual void QApplication::polish ( QWidget ) [virtual]
static void QApplication::postEvent ( QObject receiver,
QEvent event 
) [static]
void QApplication::postEvent ( QObject receiver,
QEvent event 
) [static]

Adds the event event with the object receiver as the receiver of the event, to an event queue and returns immediately.

The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted.

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

Ver también:
sendEvent(), notify()
void QApplication::processEvents ( int  maxtime)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Processes pending events for maxtime milliseconds or until there are no more events to process, whichever is shorter.

You can call this function occasionally when you program is busy doing a long operation (e.g. copying a file).

Ver también:
exec(), QTimer, QEventLoop::processEvents()
void QApplication::processEvents ( )
void QApplication::processEvents ( )

Processes pending events, for 3 seconds or until there are no more events to process, whichever is shorter.

You can call this function occasionally when your program is busy performing a long operation (e.g. copying a file).

Ver también:
exec(), QTimer, QEventLoop::processEvents()
void QApplication::processEvents ( int  maxtime)
void QApplication::processOneEvent ( )
void QApplication::processOneEvent ( )

Waits for an event to occur, processes it, then returns.

This function is useful for adapting Qt to situations where the event processing must be grafted onto existing program loops.

Using this function in new applications may be an indication of design problems.

Ver también:
processEvents(), exec(), QTimer
void QApplication::quit ( ) [slot]
void QApplication::quit ( ) [slot]

Tells the application to exit with return code 0 (success). Equivalent to calling QApplication::exit( 0 ).

It's common to connect the lastWindowClosed() signal to quit(), and you also often connect e.g. QButton::clicked() or signals in QAction, QPopupMenu or QMenuBar to it.

Example:

    QPushButton *quitButton = new QPushButton( "Quit" );
    connect( quitButton, SIGNAL(clicked()), qApp, SLOT(quit()) );
Ver también:
exit() aboutToQuit() lastWindowClosed() QAction
static void QApplication::removeLibraryPath ( const QString ) [static]
void QApplication::removeLibraryPath ( const QString path) [static]

Removes path from the library path list. If path is empty or not in the path list, the list is not changed.

Ver también:
addLibraryPath(), libraryPaths(), setLibraryPaths()
static void QApplication::removePostedEvents ( QObject receiver) [static]
void QApplication::removePostedEvents ( QObject receiver) [static]

Removes all events posted using postEvent() for receiver.

The events are not dispatched, instead they are removed from the queue. You should never need to call this function. If you do call it, be aware that killing events may cause receiver to break one or more invariants.

void QApplication::removeTranslator ( QTranslator )
void QApplication::removeTranslator ( QTranslator mf)

Removes the message file mf from the list of message files used by this application. (It does not delete the message file from the file system.)

Ver también:
installTranslator() translate(), QObject::tr()
void QApplication::restoreOverrideCursor ( ) [static]

Undoes the last setOverrideCursor().

If setOverrideCursor() has been called twice, calling restoreOverrideCursor() will activate the first cursor set. Calling this function a second time restores the original widgets' cursors.

Ver también:
setOverrideCursor(), overrideCursor().
static void QApplication::restoreOverrideCursor ( ) [static]
static bool QApplication::reverseLayout ( ) [static]
bool QApplication::reverseLayout ( ) [static]

Returns TRUE if all dialogs and widgets will be laid out in a mirrored (right to left) fashion. Returns FALSE if dialogs and widgets will be laid out left to right.

Ver también:
setReverseLayout()
void QApplication::saveState ( QSessionManager sm) [virtual]

This function deals with session management. It is invoked when the session manager wants the application to preserve its state for a future session.

For example, a text editor would create a temporary file that includes the current contents of its edit buffers, the location of the cursor and other aspects of the current editing session.

Note that you should never exit the application within this function. Instead, the session manager may or may not do this afterwards, depending on the context. Futhermore, most session managers will very likely request a saved state immediately after the application has been started. This permits the session manager to learn about the application's restart policy.

Atención:
Within this function, no user interaction is possible, unless you ask the session manager sm for explicit permission. See QSessionManager::allowsInteraction() and QSessionManager::allowsErrorInteraction() for details.
Ver también:
isSessionRestored(), sessionId(), commitData(), the Session Management overview
virtual void QApplication::saveState ( QSessionManager sm) [virtual]
static bool QApplication::sendEvent ( QObject receiver,
QEvent event 
) [static]
bool QApplication::sendEvent ( QObject receiver,
QEvent event 
) [inline, static]

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

The event is not deleted when the event has been sent. The normal approach is to create the event on the stack, e.g.

    QMouseEvent me( QEvent::MouseButtonPress, pos, 0, 0 );
    QApplication::sendEvent( mainWindow, &me );

If you create the event on the heap you must delete it.

Ver también:
postEvent(), notify()
void QApplication::sendPostedEvents ( ) [static]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Dispatches all posted events, i.e. empties the event queue.

static void QApplication::sendPostedEvents ( QObject receiver,
int  event_type 
) [static]
void QApplication::sendPostedEvents ( QObject receiver,
int  event_type 
) [static]

Immediately dispatches all events which have been previously queued with QApplication::postEvent() and which are for the object receiver and have the event type event_type.

Note that events from the window system are not dispatched by this function, but by processEvents().

If receiver is null, the events of event_type are sent for all objects. If event_type is 0, all the events are sent for receiver.

static void QApplication::sendPostedEvents ( ) [static]
QString QApplication::sessionId ( ) const [inline]

Returns the current session's identifier.

If the application has been restored from an earlier session, this identifier is the same as it was in that previous session.

The session identifier is guaranteed to be unique both for different applications and for different instances of the same application.

Ver también:
isSessionRestored(), sessionKey(), commitData(), saveState()
QString QApplication::sessionId ( ) const
QString QApplication::sessionKey ( ) const [inline]

Returns the session key in the current session.

If the application has been restored from an earlier session, this key is the same as it was when the previous session ended.

The session key changes with every call of commitData() or saveState().

Ver también:
isSessionRestored(), sessionId(), commitData(), saveState()
QString QApplication::sessionKey ( ) const
void QApplication::setColorMode ( QApplication::ColorMode  mode) [static]
static void QApplication::setColorMode ( QApplication::ColorMode  ) [static]
void QApplication::setColorSpec ( int  spec) [static]

Sets the color specification for the application to spec.

The color specification controls how the application allocates colors when run on a display with a limited amount of colors, e.g. 8 bit / 256 color displays.

The color specification must be set before you create the QApplication object.

The options are: QApplication::NormalColor. This is the default color allocation strategy. Use this option if your application uses buttons, menus, texts and pixmaps with few colors. With this option, the application uses system global colors. This works fine for most applications under X11, but on Windows machines it may cause dithering of non-standard colors. QApplication::CustomColor. Use this option if your application needs a small number of custom colors. On X11, this option is the same as NormalColor. On Windows, Qt creates a Windows palette, and allocates colors to it on demand. QApplication::ManyColor. Use this option if your application is very color hungry (e.g. it requires thousands of colors). Under X11 the effect is: For 256-color displays which have at best a 256 color true color visual, the default visual is used, and colors are allocated from a color cube. The color cube is the 6x6x6 (216 color) "Web palette"*, but the number of colors can be changed by the -ncols option. The user can force the application to use the true color visual with the -visual option. For 256-color displays which have a true color visual with more than 256 colors, use that visual. Silicon Graphics X servers have this feature, for example. They provide an 8 bit visual by default but can deliver true color when asked. On Windows, Qt creates a Windows palette, and fills it with a color cube.

Be aware that the CustomColor and ManyColor choices may lead to colormap flashing: The foreground application gets (most) of the available colors, while the background windows will look less attractive.

Example:

  int main( int argc, char **argv )
  {
      QApplication::setColorSpec( QApplication::ManyColor );
      QApplication a( argc, argv );
      ...
  }

QColor provides more functionality for controlling color allocation and freeing up certain colors. See QColor::enterAllocContext() for more information.

To check what mode you end up with, call QColor::numBitPlanes() once the QApplication object exists. A value greater than 8 (typically 16, 24 or 32) means true color.

* The color cube used by Qt has 216 colors whose red, green, and blue components always have one of the following values: 0x00, 0x33, 0x66, 0x99, 0xCC, or 0xFF.

Ver también:
colorSpec(), QColor::numBitPlanes(), QColor::enterAllocContext()
static void QApplication::setColorSpec ( int  ) [static]
void QApplication::setCursorFlashTime ( int  msecs) [static]

Sets the text cursor's flash time to msecs milliseconds. The flash time is the time required to display, invert and restore the caret display: A full flash cycle. Usually, the text cursor is displayed for msecs/2 milliseconds, then hidden for msecs/2 milliseconds, but this may vary.

Note that on Microsoft Windows, calling this function sets the cursor flash time for all windows.

Ver también:
cursorFlashTime()

Sets the text cursor's flash (blink) time to msecs milliseconds. The flash time is the time required to display, invert and restore the caret display. Usually the text cursor is displayed for msecs/2 milliseconds, then hidden for msecs/2 milliseconds, but this may vary.

Note that on Microsoft Windows, calling this function sets the cursor flash time for all windows.

Ver también:
cursorFlashTime()
static void QApplication::setCursorFlashTime ( int  ) [static]
void QApplication::setDefaultCodec ( QTextCodec )
void QApplication::setDefaultCodec ( QTextCodec codec)

This is the same as QTextCodec::setCodecForTr().

static void QApplication::setDesktopSettingsAware ( bool  ) [static]
void QApplication::setDesktopSettingsAware ( bool  on) [static]

By default, Qt will try to use the current standard colors, fonts etc., from the underlying window system's desktop settings, and use them for all relevant widgets. This behavior can be switched off by calling this function with on set to FALSE.

This static function must be called before creating the QApplication object, like this:

  int main( int argc, char** argv ) {
    QApplication::setDesktopSettingsAware( FALSE ); // I know better than the user
    QApplication myApp( argc, argv ); // Use default fonts & colors
    ...
  }
Ver también:
desktopSettingsAware()
static void QApplication::setDoubleClickInterval ( int  ) [static]
void QApplication::setDoubleClickInterval ( int  ms) [static]

Sets the time limit that distinguishes a double click from two consecutive mouse clicks to ms milliseconds.

Note that on Microsoft Windows, calling this function sets the double click interval for all windows.

Ver también:
doubleClickInterval()
static void QApplication::setEffectEnabled ( Qt::UIEffect  ,
bool  enable = TRUE 
) [static]
void QApplication::setEffectEnabled ( Qt::UIEffect  effect,
bool  enable = TRUE 
) [static]

Enables the UI effect effect if enable is TRUE, otherwise the effect will not be used.

Note: All effects are disabled on screens running at less than 16-bit color depth.

Ver también:
isEffectEnabled(), Qt::UIEffect, setDesktopSettingsAware()
void QApplication::setFont ( const QFont font,
bool  informWidgets = FALSE,
const char *  className = 0 
) [static]

Changes the default application font to font. If informWidgets is TRUE, then existing widgets are informed about the change and may adjust themselves to the new application setting. If informWidgets is FALSE, the change only affects newly created widgets. If className is passed, the change applies only to classes that inherit className (as reported by QObject::inherits()).

On application start-up, the default font depends on the window system. It can vary depending on both the window system version and the locale. This function lets you override the default font; but overriding may be a bad idea because, for example, some locales need extra-large fonts to support their special characters.

Ver también:
font(), fontMetrics(), QWidget::setFont()
static void QApplication::setFont ( const QFont ,
bool  informWidgets = FALSE,
const char *  className = 0 
) [static]
static void QApplication::setGlobalMouseTracking ( bool  enable) [static]
void QApplication::setGlobalMouseTracking ( bool  enable) [static]

Enables global mouse tracking if enable is TRUE or disables it if enable is false.

Enabling global mouse tracking makes it possible for widget event filters or application event filters to get all mouse move events, even when no button is depressed. This is useful for special GUI elements, e.g. tool tips.

Global mouse tracking does not affect widgets and their mouseMoveEvent(). For a widget to get mouse move events when no button is depressed, it must do QWidget::setMouseTracking(TRUE).

This function uses an internal counter. Each setGlobalMouseTracking(TRUE) must have a corresponding setGlobalMouseTracking(false):

    // at this point global mouse tracking is off
    QApplication::setGlobalMouseTracking( TRUE );
    QApplication::setGlobalMouseTracking( TRUE );
    QApplication::setGlobalMouseTracking( false );
    // at this point it's still on
    QApplication::setGlobalMouseTracking( false );
    // but now it's off
Ver también:
hasGlobalMouseTracking(), QWidget::hasMouseTracking()

Enables global mouse tracking if enable is TRUE, or disables it if enable is FALSE.

Enabling global mouse tracking makes it possible for widget event filters or application event filters to get all mouse move events, even when no button is depressed. This is useful for special GUI elements, e.g. tooltips.

Global mouse tracking does not affect widgets and their mouseMoveEvent(). For a widget to get mouse move events when no button is depressed, it must do QWidget::setMouseTracking(TRUE).

This function uses an internal counter. Each setGlobalMouseTracking(TRUE) must have a corresponding setGlobalMouseTracking(FALSE):

        // at this point global mouse tracking is off
        QApplication::setGlobalMouseTracking( TRUE );
        QApplication::setGlobalMouseTracking( TRUE );
        QApplication::setGlobalMouseTracking( FALSE );
        // at this point it's still on
        QApplication::setGlobalMouseTracking( FALSE );
        // but now it's off
Ver también:
hasGlobalMouseTracking(), QWidget::hasMouseTracking()
static void QApplication::setGlobalStrut ( const QSize ) [static]
void QApplication::setGlobalStrut ( const QSize strut) [static]

Sets the application's global strut to strut.

The strut is a size object whose dimensions are the minimum that any GUI element that the user can interact with should have. For example no button should be resized to be smaller than the global strut size.

The strut size should be considered when reimplementing GUI controls that may be used on touch-screens or similar IO-devices.

Example:

  QSize& WidgetClass::sizeHint() const
  {
      return QSize( 80, 25 ).expandedTo( QApplication::globalStrut() );
  }
Ver también:
globalStrut()
void QApplication::setLibraryPaths ( const QStringList paths) [static]

Sets the list of directories to search when loading libraries to paths. All existing paths will be deleted and the path list will consist of the paths given in paths.

Ver también:
libraryPaths(), addLibraryPath(), removeLibraryPath(), QLibrary
static void QApplication::setLibraryPaths ( const QStringList ) [static]
virtual void QApplication::setMainWidget ( QWidget ) [virtual]
void QApplication::setMainWidget ( QWidget mainWidget) [virtual]

Sets the application's main widget to mainWidget.

In most respects the main widget is like any other widget, except that if it is closed, the application exits. Note that QApplication does not take ownership of the mainWidget, so if you create your main widget on the heap you must delete it yourself.

You need not have a main widget; connecting lastWindowClosed() to quit() is an alternative.

For X11, this function also resizes and moves the main widget according to the -geometry command-line option, so you should set the default geometry (using QWidget::setGeometry()) before calling setMainWidget().

Ver también:
mainWidget(), exec(), quit()
void QApplication::setOverrideCursor ( const QCursor cursor,
bool  replace = FALSE 
) [static]

Sets the application override cursor to cursor.

Application override cursors are intended for showing the user that the application is in a special state, for example during an operation that might take some time.

This cursor will be displayed in all the application's widgets until restoreOverrideCursor() or another setOverrideCursor() is called.

Application cursors are stored on an internal stack. setOverrideCursor() pushes the cursor onto the stack, and restoreOverrideCursor() pops the active cursor off the stack. Every setOverrideCursor() must eventually be followed by a corresponding restoreOverrideCursor(), otherwise the stack will never be emptied.

If replace is TRUE, the new cursor will replace the last override cursor (the stack keeps its depth). If replace is FALSE, the new stack is pushed onto the top of the stack.

Example:

Ver también:
overrideCursor(), restoreOverrideCursor(), QWidget::setCursor()
static void QApplication::setOverrideCursor ( const QCursor ,
bool  replace = FALSE 
) [static]
static void QApplication::setPalette ( const QPalette ,
bool  informWidgets = FALSE,
const char *  className = 0 
) [static]
void QApplication::setPalette ( const QPalette palette,
bool  informWidgets = FALSE,
const char *  className = 0 
) [static]

Changes the default application palette to palette. If informWidgets is TRUE, then existing widgets are informed about the change and may adjust themselves to the new application setting. If informWidgets is FALSE, the change only affects newly created widgets.

If className is passed, the change applies only to widgets that inherit className (as reported by QObject::inherits()). If className is left 0, the change affects all widgets, thus overriding any previously set class specific palettes.

The palette may be changed according to the current GUI style in QStyle::polish().

Ver también:
QWidget::setPalette(), palette(), QStyle::polish()
static void QApplication::setReverseLayout ( bool  b) [static]
void QApplication::setReverseLayout ( bool  b) [static]

If b is TRUE, all dialogs and widgets will be laid out in a mirrored fashion, as required by right to left languages such as Arabic and Hebrew. If b is FALSE, dialogs and widgets are laid out left to right.

Changing this flag in runtime does not cause a relayout of already instantiated widgets.

Ver también:
reverseLayout()
static void QApplication::setStartDragDistance ( int  l) [static]
void QApplication::setStartDragDistance ( int  l) [static]

Sets the distance after which a drag should start to l pixels.

Ver también:
startDragDistance()
void QApplication::setStartDragTime ( int  ms) [static]

Sets the time after which a drag should start to ms ms.

Ver también:
startDragTime()
static void QApplication::setStartDragTime ( int  ms) [static]
QStyle * QApplication::setStyle ( const QString style) [static]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Requests a QStyle object for style from the QStyleFactory.

The string must be one of the QStyleFactory::keys(), typically one of "windows", "motif", "cde", "motifplus", "platinum", "sgi" and "compact". Depending on the platform, "windowsxp", "aqua" or "macintosh" may be available.

A later call to the QApplication constructor will override the requested style when a "-style" option is passed in as a commandline parameter.

Returns 0 if an unknown style is passed, otherwise the QStyle object returned is set as the application's GUI style.

static void QApplication::setStyle ( QStyle ) [static]
void QApplication::setStyle ( QStyle style) [static]

Sets the application's GUI style to style. Ownership of the style object is transferred to QApplication, so QApplication will delete the style object on application exit or when a new style is set.

Example usage:

When switching application styles, the color palette is set back to the initial colors or the system defaults. This is necessary since certain styles have to adapt the color palette to be fully style-guide compliant.

Ver también:
style(), QStyle, setPalette(), desktopSettingsAware()
static QStyle* QApplication::setStyle ( const QString ) [static]
static void QApplication::setWheelScrollLines ( int  ) [static]
void QApplication::setWheelScrollLines ( int  n) [static]

Sets the number of lines to scroll when the mouse wheel is rotated to n.

If this number exceeds the number of visible lines in a certain widget, the widget should interpret the scroll operation as a single page up / page down operation instead.

Ver también:
wheelScrollLines()
void QApplication::setWinStyleHighlightColor ( const QColor c) [inline, static]

Sets the color used to mark selections in windows style for all widgets in the application. Will repaint all widgets if the color is changed.

The default color is darkBlue.

Ver también:
winStyleHighlightColor()
static void QApplication::setWinStyleHighlightColor ( const QColor c) [inline, static]
static int QApplication::startDragDistance ( ) [static]
int QApplication::startDragDistance ( ) [static]

If you support drag and drop in you application and a drag should start after a mouse click and after moving the mouse a certain distance, you should use the value which this method returns as the distance.

For example, if the mouse position of the click is stored in startPos and the current position (e.g. in the mouse move event) is currPos, you can find out if a drag should be started with code like this:

  if ( ( startPos - currPos ).manhattanLength() >
       QApplication::startDragDistance() )
    startTheDrag();

Qt uses this value internally, e.g. in QFileDialog.

The default value is 4 pixels.

Ver también:
setStartDragDistance(), startDragTime(), QPoint::manhattanLength()
static int QApplication::startDragTime ( ) [static]
int QApplication::startDragTime ( ) [static]

If you support drag and drop in you application and a drag should start after a mouse click and after a certain time elapsed, you should use the value which this method returns as the delay (in ms).

Qt also uses this delay internally, e.g. in QTextEdit and QLineEdit, for starting a drag.

The default value is 500 ms.

Ver también:
setStartDragTime(), startDragDistance()
bool QApplication::startingUp ( ) [static]

Returns TRUE if an application object has not been created yet; otherwise returns FALSE.

Ver también:
closingDown()
static bool QApplication::startingUp ( ) [static]
QStyle & QApplication::style ( ) [static]

Returns the application's style object.

Ver también:
setStyle(), QStyle
static QStyle& QApplication::style ( ) [static]
static void QApplication::syncX ( ) [static]
void QApplication::syncX ( ) [static]

Synchronizes with the X server in the X11 implementation. This normally takes some time. Does nothing on other platforms.

Ver también:
flushX()
QWidgetList * QApplication::topLevelWidgets ( ) [static]

Returns a list of the top level widgets in the application.

The list is created using new and must be deleted by the caller.

The list is empty (QPtrList::isEmpty()) if there are no top level widgets.

Note that some of the top level widgets may be hidden, for example the tooltip if no tooltip is currently shown.

Example:

    // Show all hidden top level widgets.
    QWidgetList  *list = QApplication::topLevelWidgets();
    QWidgetListIt it( *list );  // iterate over the widgets
    QWidget * w;
    while ( (w=it.current()) != 0 ) { // for each top level widget...
  ++it;
  if ( !w->isVisible() )
      w->show();
    }
    delete list;    // delete the list, not the widgets
Atención:
Delete the list as soon you have finished using it. The widgets in the list may be deleted by someone else at any time.
Ver también:
allWidgets(), QWidget::isTopLevel(), QWidget::isVisible(), QPtrList::isEmpty()
static QWidgetList* QApplication::topLevelWidgets ( ) [static]
QString QApplication::translate ( const char *  context,
const char *  sourceText,
const char *  comment = 0,
Encoding  encoding = DefaultCodec 
) const [virtual]

Returns the translation text for sourceText, by querying the installed messages files. The message files are searched from the most recently installed message file back to the first installed message file.

QObject::tr() and QObject::trUtf8() provide this functionality more conveniently.

context is typically a class name (e.g., "MyDialog") and sourceText is either English text or a short identifying text, if the output text will be very long (as for help texts).

comment is a disambiguating comment, for when the same sourceText is used in different roles within the same context. By default, it is null. encoding indicates the 8-bit encoding of character stings

See the QTranslator documentation for more information about contexts and comments.

If none of the message files contain a translation for sourceText in context, this function returns a QString equivalent of sourceText. The encoding of sourceText is specified by encoding; it defaults to DefaultCodec.

This function is not virtual. You can use alternative translation techniques by subclassing QTranslator.

Atención:
This method is reentrant only if all translators are installed before calling this method. Installing or removing translators while performing translations is not supported. Doing so will most likely result in crashes or other undesirable behavior.
Ver también:
QObject::tr() installTranslator() defaultCodec()
virtual QString QApplication::translate ( const char *  context,
const char *  key,
const char *  comment = 0,
Encoding  encoding = DefaultCodec 
) const [virtual]
Type QApplication::type ( ) const
QApplication::Type QApplication::type ( ) const

Returns the type of application, Tty, GuiClient or GuiServer.

void QApplication::wakeUpGuiThread ( )
void QApplication::wakeUpGuiThread ( )

Wakes up the GUI thread.

Ver también:
guiThreadAwake() Thread Support in Qt
int QApplication::wheelScrollLines ( ) [static]

Returns the number of lines to scroll when the mouse wheel is rotated.

Ver también:
setWheelScrollLines()
static int QApplication::wheelScrollLines ( ) [static]
static QWidget* QApplication::widgetAt ( const QPoint ,
bool  child = FALSE 
) [static]
QWidget * QApplication::widgetAt ( int  x,
int  y,
bool  child = FALSE 
) [static]

Returns a pointer to the widget at global screen position (x,y), or a null pointer if there is no Qt widget there.

If child is false and there is a child widget at position (x,y), the top-level widget containing it is returned. If child is TRUE the child widget at position (x,y) is returned.

This function is normally rather slow.

Ver también:
QCursor::pos(), QWidget::grabMouse(), QWidget::grabKeyboard()

Returns a pointer to the widget at global screen position (x, y), or 0 if there is no Qt widget there.

If child is FALSE and there is a child widget at position (x, y), the top-level widget containing it is returned. If child is TRUE the child widget at position (x, y) is returned.

This function is normally rather slow.

Ver también:
QCursor::pos(), QWidget::grabMouse(), QWidget::grabKeyboard()
QWidget * QApplication::widgetAt ( const QPoint pos,
bool  child = FALSE 
) [inline, static]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta.

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta.

Returns a pointer to the widget at global screen position pos, or 0 if there is no Qt widget there.

If child is FALSE and there is a child widget at position pos, the top-level widget containing it is returned. If child is TRUE the child widget at position pos is returned.

static QWidget* QApplication::widgetAt ( int  x,
int  y,
bool  child = FALSE 
) [static]
static const QColor& QApplication::winStyleHighlightColor ( ) [inline, static]
const QColor & QApplication::winStyleHighlightColor ( ) [inline, static]

Returns the color used to mark selections in windows style.

Ver también:
setWinStyleHighlightColor()

Documentación de las funciones relacionadas y clases amigas

FLApplication [friend]
void Q_ASSERT ( bool  test) [related]

Prints a warning message containing the source code file name and line number if test is FALSE.

This is really a macro defined in qglobal.h.

Q_ASSERT is useful for testing pre- and post-conditions.

Example:

        //
        // File: div.cpp
        //

        #include <qglobal.h>

        int divide( int a, int b )
        {
            Q_ASSERT( b != 0 );                 // this is line 9
            return a/b;
        }

If b is zero, the Q_ASSERT statement will output the following message using the qWarning() function:

        ASSERT: "b != 0" in div.cpp (9)
Ver también:
qWarning(), Debugging
void Q_CHECK_PTR ( void *  p) [related]

If p is 0, prints a warning message containing the source code file name and line number, saying that the program ran out of memory.

This is really a macro defined in qglobal.h.

Example:

        int *a;

        Q_CHECK_PTR( a = new int[80] );  // WRONG!

        a = new (nothrow) int[80];       // Right
        Q_CHECK_PTR( a );
Ver también:
qWarning(), Debugging
QAccelManager [friend]
Q_EXPORT void qAddPostRoutine ( QtCleanUpFunction  p) [related]

Adds a global routine that will be called from the QApplication destructor. This function is normally used to add cleanup routines for program-wide functionality.

The function given by p should take no arguments and return nothing, like this:

    static int *global_ptr = 0;

    static void cleanup_ptr()
    {
  delete [] global_ptr;
  global_ptr = 0;
    }

    void init_ptr()
    {
  global_ptr = new int[100];  // allocate data
  qAddPostRoutine( cleanup_ptr ); // delete later
    }

Note that for an application- or module-wide cleanup, qAddPostRoutine() is often not suitable. People have a tendency to make such modules dynamically loaded, and then unload those modules long before the QApplication destructor is called, for example.

For modules and libraries, using a reference-counted initialization manager or Qt' parent-child delete mechanism may be better. Here is an example of a private class which uses the parent-child mechanism to call a cleanup function at the right time:

    class MyPrivateInitStuff: public QObject {
    private:
  MyPrivateInitStuff( QObject * parent ): QObject( parent) {
      // initialization goes here
  }
  MyPrivateInitStuff * p;

    public:
  static MyPrivateInitStuff * initStuff( QObject * parent ) {
      if ( !p )
    p = new MyPrivateInitStuff( parent );
      return p;
  }

  ~MyPrivateInitStuff() {
      // cleanup (the "post routine") goes here
  }
    }

By selecting the right parent widget/object, this can often be made to clean up the module's data at the exact right moment.

void qDebug ( const char *  msg,
  ... 
) [related]

Prints a debug message msg, or calls the message handler (if it has been installed).

This function takes a format string and a list of arguments, similar to the C printf() function.

Example:

        qDebug( "my window handle = %x", myWidget->id() );

Under X11, the text is printed to stderr. Under Windows, the text is sent to the debugger.

Atención:
The internal buffer is limited to 8196 bytes (including the '\0'-terminator).
Passing (const char *)0 as argument to qDebug might lead to crashes on certain platforms due to the platforms printf implementation.
Ver también:
qWarning(), qFatal(), qInstallMsgHandler(), Debugging
QDialog [friend]
QETWidget [friend]
QEvent [friend]
QEventLoop [friend]
void qFatal ( const char *  msg,
  ... 
) [related]

Prints a fatal error message msg and exits, or calls the message handler (if it has been installed).

This function takes a format string and a list of arguments, similar to the C printf() function.

Example:

        int divide( int a, int b )
        {
            if ( b == 0 )                               // program error
                qFatal( "divide: cannot divide by zero" );
            return a/b;
        }

Under X11, the text is printed to stderr. Under Windows, the text is sent to the debugger.

Atención:
The internal buffer is limited to 8196 bytes (including the '\0'-terminator).
Passing (const char *)0 as argument to qFatal might lead to crashes on certain platforms due to the platforms printf implementation.
Ver también:
qDebug(), qWarning(), qInstallMsgHandler(), Debugging
QtMsgHandler qInstallMsgHandler ( QtMsgHandler  h) [related]

Installs a Qt message handler h. Returns a pointer to the message handler previously defined.

The message handler is a function that prints out debug messages, warnings and fatal error messages. The Qt library (debug version) contains hundreds of warning messages that are printed when internal errors (usually invalid function arguments) occur. If you implement your own message handler, you get total control of these messages.

The default message handler prints the message to the standard output under X11 or to the debugger under Windows. If it is a fatal message, the application aborts immediately.

Only one message handler can be defined, since this is usually done on an application-wide basis to control debug output.

To restore the message handler, call qInstallMsgHandler(0).

Example:

        #include <qapplication.h>
        #include <stdio.h>
        #include <stdlib.h>

        void myMessageOutput( QtMsgType type, const char *msg )
        {
            switch ( type ) {
                case QtDebugMsg:
                    fprintf( stderr, "Debug: %s\n", msg );
                    break;
                case QtWarningMsg:
                    fprintf( stderr, "Warning: %s\n", msg );
                    break;
                case QtFatalMsg:
                    fprintf( stderr, "Fatal: %s\n", msg );
                    abort();                    // deliberately core dump
            }
        }

        int main( int argc, char **argv )
        {
            qInstallMsgHandler( myMessageOutput );
            QApplication a( argc, argv );
            ...
            return a.exec();
        }
Ver también:
qDebug(), qWarning(), qFatal(), Debugging
bool qSysInfo ( int wordSize,
bool bigEndian 
) [related]

Obtains information about the system.

The system's word size in bits (typically 32) is returned in wordSize. The *bigEndian is set to TRUE if this is a big-endian machine, or to FALSE if this is a little-endian machine.

In debug mode, this function calls qFatal() with a message if the computer is truly weird (i.e. different endianness for 16 bit and 32 bit integers); in release mode it returns FALSE.

void qSystemWarning ( const char *  msg,
int  code 
) [related]

Prints the message msg and uses code to get a system specific error message. When code is -1 (the default), the system's last error code will be used if possible. Use this method to handle failures in platform specific API calls.

This function does nothing when Qt is built with QT_NO_DEBUG defined.

Q_EXPORT void qt_ucm_initialize ( QApplication theApp) [friend]
Q_EXPORT void qt_ucm_initialize ( QApplication theApp) [friend]
QTranslator [friend]
const char * qVersion ( ) [related]

Returns the Qt version number as a string, for example, "2.3.0" or "3.0.5".

The QT_VERSION define has the numeric value in the form: 0xmmiibb (m = major, i = minor, b = bugfix). For example, Qt 3.0.5's QT_VERSION is 0x030005.

void qWarning ( const char *  msg,
  ... 
) [related]

Prints a warning message msg, or calls the message handler (if it has been installed).

This function takes a format string and a list of arguments, similar to the C printf() function.

Example:

        void f( int c )
        {
            if ( c > 200 )
                qWarning( "f: bad argument, c == %d", c );
        }

Under X11, the text is printed to stderr. Under Windows, the text is sent to the debugger.

Atención:
The internal buffer is limited to 8196 bytes (including the '\0'-terminator).
Passing (const char *)0 as argument to qWarning might lead to crashes on certain platforms due to the platforms printf implementation.
Ver también:
qDebug(), qFatal(), qInstallMsgHandler(), Debugging
QWidget [friend]

Reimplementado de QObject.


La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'