📄 qapplication.3qt
字号:
.BI "void \fBflushX\fR ()".br.ti -1c.BI "void \fBflush\fR ()".br.ti -1c.BI "void \fBsyncX\fR ()".br.ti -1c.BI "void \fBbeep\fR ()".br.ti -1c.BI "void setWinStyleHighlightColor ( const QColor & c ) \fI(obsolete)\fR".br.ti -1c.BI "const QColor & winStyleHighlightColor () \fI(obsolete)\fR".br.ti -1c.BI "void \fBsetDesktopSettingsAware\fR ( bool on )".br.ti -1c.BI "bool \fBdesktopSettingsAware\fR ()".br.ti -1c.BI "void \fBsetCursorFlashTime\fR ( int msecs )".br.ti -1c.BI "int \fBcursorFlashTime\fR ()".br.ti -1c.BI "void \fBsetDoubleClickInterval\fR ( int ms )".br.ti -1c.BI "int \fBdoubleClickInterval\fR ()".br.ti -1c.BI "void \fBsetWheelScrollLines\fR ( int n )".br.ti -1c.BI "int \fBwheelScrollLines\fR ()".br.ti -1c.BI "void \fBsetGlobalStrut\fR ( const QSize & strut )".br.ti -1c.BI "QSize \fBglobalStrut\fR ()".br.ti -1c.BI "void \fBsetLibraryPaths\fR ( const QStringList & paths )".br.ti -1c.BI "QStringList \fBlibraryPaths\fR ()".br.ti -1c.BI "void \fBaddLibraryPath\fR ( const QString & path )".br.ti -1c.BI "void \fBremoveLibraryPath\fR ( const QString & path )".br.ti -1c.BI "void \fBsetStartDragTime\fR ( int ms )".br.ti -1c.BI "int \fBstartDragTime\fR ()".br.ti -1c.BI "void \fBsetStartDragDistance\fR ( int l )".br.ti -1c.BI "int \fBstartDragDistance\fR ()".br.ti -1c.BI "void \fBsetReverseLayout\fR ( bool b )".br.ti -1c.BI "bool \fBreverseLayout\fR ()".br.ti -1c.BI "int \fBhorizontalAlignment\fR ( int align )".br.ti -1c.BI "bool \fBisEffectEnabled\fR ( Qt::UIEffect effect )".br.ti -1c.BI "void \fBsetEffectEnabled\fR ( Qt::UIEffect effect, bool enable = TRUE )".br.ti -1c.BI "QWSDecoration & \fBqwsDecoration\fR ()".br.ti -1c.BI "void \fBqwsSetDecoration\fR ( QWSDecoration * d )".br.in -1c.SH RELATED FUNCTION DOCUMENTATION.in +1c.ti -1c.BI "void \fBqAddPostRoutine\fR ( QtCleanUpFunction p )".br.ti -1c.BI "const char * \fBqVersion\fR ()".br.ti -1c.BI "bool \fBqSysInfo\fR ( int * wordSize, bool * bigEndian )".br.ti -1c.BI "void \fBqDebug\fR ( const char * msg, ... )".br.ti -1c.BI "void \fBqWarning\fR ( const char * msg, ... )".br.ti -1c.BI "void \fBqFatal\fR ( const char * msg, ... )".br.ti -1c.BI "void \fBqSystemWarning\fR ( const char * msg, int code )".br.ti -1c.BI "void \fBQ_ASSERT\fR ( bool test )".br.ti -1c.BI "void \fBQ_CHECK_PTR\fR ( void * p )".br.ti -1c.BI "QtMsgHandler \fBqInstallMsgHandler\fR ( QtMsgHandler h )".br.in -1c.SH DESCRIPTIONThe QApplication class manages the GUI application's control flow and main settings..PPIt 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..PPFor 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..PPThe QApplication object is accessible through the global pointer \fCqApp\fR. Its main areas of responsibility are:.IP.TPIt 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..IP.TPIt 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..IP.TPIt parses common command line arguments and sets its internal state accordingly. See the constructor documentation below for more details about this..IP.TPIt defines the application's look and feel, which is encapsulated in a QStyle object. This can be changed at runtime with setStyle()..IP.TPIt specifies how the application is to allocate colors. See setColorSpec() for details..IP.TPIt provides localization of strings that are visible to the user via translate()..IP.TPIt provides some magical objects like the desktop() and the clipboard()..IP.TPIt 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..IP.TPIt manages the application's mouse cursor handling, see setOverrideCursor() and setGlobalMouseTracking()..IP.TPOn the X window system, it provides functions to flush and sync the communication stream, see flushX() and syncX()..IP.TPIt 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..IP.PPThe Application walk-through example contains a typical complete main() that does the usual things with QApplication..PPSince the QApplication object does so much initialization, it \fBmust\fR be created before any other objects related to the user interface are created..PPSince it also deals with common command line arguments, it is usually a good idea to create it \fIbefore\fR any interpretation or modification of \fCargv\fR is done in the application itself. (Note also that for X11, setMainWidget() may change the main widget according to the \fC-geometry\fR option. To preserve this functionality, you must set your defaults before setMainWidget() and any overrides after.).PP<center>.nf.TSl - l. 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.TE.fi</center>.PP\fINon-GUI programs:\fR 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..PPSee also Main Window and Related Classes..SS "Member Type Documentation".SH "QApplication::ColorSpec".TP\fCQApplication::NormalColor\fR - the default color allocation policy.TP\fCQApplication::CustomColor\fR - the same as NormalColor for X11; allocates colors to a palette on demand under Windows.TP\fCQApplication::ManyColor\fR - the right choice for applications that use thousands of colors.PPSee setColorSpec() for full details..SH "QApplication::Encoding"This enum type defines the 8-bit encoding of character string arguments to translate():.TP\fCQApplication::DefaultCodec\fR - the encoding specified by QTextCodec::codecForTr() (Latin-1 if none has been set).TP\fCQApplication::UnicodeUTF8\fR - UTF-8.PPSee also QObject::tr(), QObject::trUtf8(), and QString::fromUtf8()..SH "QApplication::Type".TP\fCQApplication::Tty\fR - a console application.TP\fCQApplication::GuiClient\fR - a GUI client application.TP\fCQApplication::GuiServer\fR - a GUI server application.SH MEMBER FUNCTION DOCUMENTATION.SH "QApplication::QApplication ( int & argc, char ** argv )"Initializes the window system and constructs an application object with \fIargc\fR command line arguments in \fIargv\fR..PPThe global \fCqApp\fR pointer refers to this application object. Only one application object should be created..PPThis application object must be constructed before any paint devices (including widgets, pixmaps, bitmaps etc.)..PPNote that \fIargc\fR and \fIargv\fR might be changed. Qt removes command line arguments that it recognizes. The modified \fIargc\fR and \fIargv\fR can also be accessed later with \fCqApp->argc()\fR and \fCqApp->argv()\fR. The documentation for argv() contains a detailed description of how to process command line arguments..PPQt debugging options (not available if Qt was compiled with the QT_NO_DEBUG flag defined):.TP-nograb, tells Qt that it must never grab the mouse or the keyboard..TP-dograb (only under X11), running under a debugger can cause an implicit -nograb, use -dograb to override..TP-sync (only under X11), switches to synchronous mode for debugging..PPSee Debugging Techniques for a more detailed explanation..PPAll Qt programs automatically support the following command line options:.TP-reverse causes text to be formatted for right-to-left languages rather than in the usual left-to-right direction..TP-style= \fIstyle\fR, sets the application GUI style. Possible values are \fCmotif\fR, \fCwindows\fR, and \fCplatinum\fR. If you compiled Qt with additional styles or have additional styles as plugins these will be available to the \fC-style\fR command line option..TP-style \fIstyle\fR, is the same as listed above..TP-session= \fIsession\fR, restores the application from an earlier session..TP-session \fIsession\fR, is the same as listed above..TP-widgetcount, prints debug message at the end about number of widgets left undestroyed and maximum number of widgets existed at the same time.PPThe X11 version of Qt also supports some traditional X11 command line options:.TP-display \fIdisplay\fR, sets the X display (default is $DISPLAY)..TP-geometry \fIgeometry\fR, sets the client geometry of the main widget..TP-fn or \fC-font\fR \fIfont\fR, defines the application font. The font should be specified using an X logical font description..TP-bg or \fC-background\fR \fIcolor\fR, sets the default background color and an application palette (light and dark shades are calculated)..TP-fg or \fC-foreground\fR \fIcolor\fR, sets the default foreground color..TP-btn or \fC-button\fR \fIcolor\fR, sets the default button color..TP-name \fIname\fR, sets the application name..TP-title \fItitle\fR, sets the application title (caption)..TP-visual \fCTrueColor\fR, forces the application to use a TrueColor visual on an 8-bit display..TP-ncols \fIcount\fR, 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 \fIcount\fR 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..TP-cmap, causes the application to install a private color map on an 8-bit display..PPSee also argc() and argv()..SH "QApplication::QApplication ( int & argc, char ** argv, bool GUIenabled )"Constructs an application object with \fIargc\fR command line arguments in \fIargv\fR. If \fIGUIenabled\fR is TRUE, a GUI application is constructed, otherwise a non-GUI (console) application is created..PPSet \fIGUIenabled\fR to FALSE for programs without a graphical user interface that should be able to run without a window system..PPOn X11, the window system is initialized if \fIGUIenabled\fR is TRUE. If \fIGUIenabled\fR 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..PPThe following example shows how to create an application that uses a graphical interface when available..PP.nf.br int main( int argc, char **argv ).br {.br#ifdef Q_WS_X11.br bool useGUI = getenv( "DISPLAY" ) != 0;.br#else.br bool useGUI = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -