📄 qapplication.3qt
字号:
This function enters the main event loop (recursively). Do not call it unless you really know what you are doing..SH "QEventLoop * QApplication::eventLoop ()\fC [static]\fR"Returns the application event loop. This function will return zero if called during and after destroying QApplication..PPTo create your own instance of QEventLoop or QEventLoop subclass create it before you create the QApplication object..PPSee also QEventLoop..PPExample: distributor/distributor.ui.h..SH "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())..PPIt 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..PPGenerally 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..PPTo 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()..PPSee also quit(), exit(), processEvents(), and setMainWidget()..PPExamples:.)l helpsystem/main.cpp, life/main.cpp, network/archivesearch/main.cpp, network/ftpclient/main.cpp, opengl/main.cpp, t1/main.cpp, and t4/main.cpp..SH "void QApplication::exit ( int retcode = 0 )\fC [static]\fR"Tells the application to exit with a return code..PPAfter this function has been called, the application leaves the main event loop and returns from the call to exec(). The exec() function returns \fIretcode\fR..PPBy convention, a \fIretcode\fR of 0 means success, and any non-zero value indicates an error..PPNote that unlike the C library function of the same name, this function \fIdoes\fR return to the caller -- it is event processing that stops..PPSee also quit() and exec()..PPExamples:.)l chart/chartform.cpp, extension/mainform.ui.h, and picture/picture.cpp..SH "void QApplication::exit_loop ()"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPThis function exits from a recursive call to the main event loop. Do not call it unless you are an expert..SH "void QApplication::flush ()\fC [static]\fR"Flushes the window system specific event queues..PPIf 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..PPSee also flushX(), sendPostedEvents(), and QPainter::flush()..SH "void QApplication::flushX ()\fC [static]\fR"Flushes the X event queue in the X11 implementation. This normally returns almost immediately. Does nothing on other platforms..PPSee also syncX()..PPExample: xform/xform.cpp..SH "QWidget * QApplication::focusWidget () const"Returns the application widget that has the keyboard input focus, or 0 if no widget in this application has the focus..PPSee also QWidget::setFocus(), QWidget::focus, and activeWindow()..SH "QFont QApplication::font ( const QWidget * w = 0 )\fC [static]\fR"Returns the default font for the widget \fIw\fR, or the default application font if \fIw\fR is 0..PPSee also setFont(), fontMetrics(), and QWidget::font..PPExamples:.)l qfd/fontdisplayer.cpp, themes/metal.cpp, and themes/themes.cpp..SH "QFontMetrics QApplication::fontMetrics ()\fC [static]\fR"Returns display (screen) font metrics for the application font..PPSee also font(), setFont(), QWidget::fontMetrics(), and QPainter::fontMetrics()..SH "QSize QApplication::globalStrut ()\fC [static]\fR"Returns the application's global strut..PPThe 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..PPSee also setGlobalStrut()..SH "void QApplication::guiThreadAwake ()\fC [signal]\fR"This signal is emitted after the event loop returns from a function that could block..PPSee also wakeUpGuiThread()..SH "bool QApplication::hasGlobalMouseTracking ()\fC [static]\fR"Returns TRUE if global mouse tracking is enabled; otherwise returns FALSE..PPSee also setGlobalMouseTracking()..SH "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()..SH "int QApplication::horizontalAlignment ( int align )\fC [static]\fR"Strips out vertical alignment flags and transforms an alignment \fIalign\fR of AlignAuto into AlignLeft or AlignRight according to the language used. The other horizontal alignment flags are left untouched..SH "void QApplication::installTranslator ( QTranslator * mf )"Adds the message file \fImf\fR to the list of message files to be used for translations..PPMultiple 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..PPSee also removeTranslator(), translate(), and QTranslator::load()..PPExample: i18n/main.cpp..SH "bool QApplication::isEffectEnabled ( Qt::UIEffect effect )\fC [static]\fR"Returns TRUE if \fIeffect\fR is enabled; otherwise returns FALSE..PPBy default, Qt will try to use the desktop settings. Call setDesktopSettingsAware(FALSE) to prevent this..PPNote: All effects are disabled on screens running at less than 16-bit color depth..PPSee also setEffectEnabled() and Qt::UIEffect..SH "bool QApplication::isSessionRestored () const"Returns TRUE if the application has been restored from an earlier session; otherwise returns FALSE..PPSee also sessionId(), commitData(), and saveState()..SH "void QApplication::lastWindowClosed ()\fC [signal]\fR"This signal is emitted when the user has closed the last top level window..PPThe 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..PPFor convenience, this signal is \fInot\fR emitted for transient top level widgets such as popup menus and dialogs..PPSee also mainWidget(), topLevelWidgets(), QWidget::isTopLevel, and QWidget::close()..PPExamples:.)l addressbook/main.cpp, extension/main.cpp, helpviewer/main.cpp, mdi/main.cpp, network/archivesearch/main.cpp, qwerty/main.cpp, and regexptester/main.cpp..SH "QStringList QApplication::libraryPaths ()\fC [static]\fR"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 \fCINSTALL/plugins\fR, where \fCINSTALL\fR is the directory where Qt was installed. The directory of the application executable (NOT the working directory) is also added to the plugin paths..PPIf you want to iterate over the list, you should iterate over a copy, e.g..PP.nf.br QStringList list = app.libraryPaths();.br QStringList::Iterator it = list.begin();.br while( it != list.end() ) {.br myProcessing( *it );.br ++it;.br }.br.fi.PPSee the plugins documentation for a description of how the library paths are used..PPSee also setLibraryPaths(), addLibraryPath(), removeLibraryPath(), and QLibrary..SH "void QApplication::lock ()"Lock the Qt Library Mutex. If another thread has already locked the mutex, the calling thread will block until the other thread has unlocked the mutex..PPSee also unlock(), locked(), and Thread Support in Qt..SH "bool QApplication::locked ()"Returns TRUE if the Qt Library Mutex is locked by a different thread; otherwise returns FALSE..PP\fBWarning:\fR Due to different implementations of recursive mutexes on the supported platforms, calling this function from the same thread that previously locked the mutex will give undefined results..PPSee also lock(), unlock(), and Thread Support in Qt..SH "int QApplication::loopLevel () const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPReturns the current loop level..SH "bool QApplication::macEventFilter ( EventHandlerCallRef, EventRef )\fC [virtual]\fR"This virtual function is only implemented under Macintosh..PPIf you create an application that inherits QApplication and reimplement this function, you get direct access to all Carbon Events that are received from the MacOS..PPReturn TRUE if you want to stop the event from being processed. Return FALSE for normal event dispatching..SH "QWidget * QApplication::mainWidget () const"Returns the main application widget, or 0 if there is no main widget..PPSee also setMainWidget()..SH "bool QApplication::notify ( QObject * receiver, QEvent * e )\fC [virtual]\fR"Sends event \fIe\fR to \fIreceiver\fR: \fIreceiver\fR->event(\fIe\fR). Returns the value that is returned from the receiver's event handler..PPFor 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)..PPThere are five different ways that events can be processed; reimplementing this virtual function is just one of them. All five approaches are listed below: <ol type=1>.TPReimplementing this function. This is very powerful, providing complete control; but only one subclass can be qApp..IP.TPInstalling 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..IP.TPReimplementing 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..IP.TPInstalling an event filter on the object. Such an event filter gets all the events except Tab and Shift-Tab key presses..IP.TPReimplementing paintEvent(), mousePressEvent() and so on. This is the commonest, easiest and least powerful way..PPSee also QObject::event() and installEventFilter()..SH "QCursor * QApplication::overrideCursor ()\fC [static]\fR"Returns the active application override cursor..PPThis function returns 0 if no application cursor has been defined (i.e. the internal cursor stack is empty)..PPSee also setOverrideCursor() and restoreOverrideCursor()..SH "QPalette QApplication::palette ( const QWidget * w = 0 )\fC [static]\fR"Returns the application palette..PPIf a widget is passed in \fIw\fR, 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..PPSee also setPalette() and QWidget::palette..PPExamples:.)l desktop/desktop.cpp, themes/metal.cpp, and themes/wood.cpp..SH "void QApplication::polish ( QWidget * w )\fC [virtual]\fR"Initialization of the appearance of the widget \fIw\fR \fIbefore\fR it is first shown..PPUsually widgets call this automatically when they are polished. It may be used to do some style-based central customization of widgets..PPNote 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..PPSee also QStyle::polish(), QWidget::polish(), setPalette(), and setFont()..SH "void QApplication::postEvent ( QObject * receiver, QEvent * event )\fC [static]\fR"\fBNote:\fR This function is thread-safe when Qt is built withthread support.</p> Adds the event \fIevent\fR with the object \fIreceiver\fR as the receiver of the event, to an event queue and returns immediately..PPThe 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..PPWhen control returns to the main event loop, all events that are stored in the queue will be sent using the notify() function..PPSee also sendEvent() and notify()..SH "void QApplication::processEvents ()"Processes pending events, for 3 seconds or until there are no more events to process, whichever is shorter..PPYou can call this function occasionally when your program is busy performing a long operation (e.g. copying a file)..PPSee also exec(), QTimer, and QEventLoop::processEvents()..PPExamples:.)l fileiconview/qfileiconview.cpp and network/ftpclient/main.cpp..SH "void QApplication::processEvents ( int maxtime )"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPProcesses pending events for \fImaxtime\fR milliseconds or until there are no more events to process, whichever is shorter..PPYou can call this function occasionally when you program is busy doing a long operation (e.g. copying a file)..PPSee also exec(), QTimer, and QEventLoop::processEvents()..SH "void QApplication::processOneEvent ()"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPWaits for an event to occur, processes it, then returns..PPThis function is useful for adapting Qt to situations where the event processing must be grafted onto existing program loops..PPUsing this function in new applications may be an indication of design problems..PPSee also processEvents(), exec(), and QTimer..SH "void QApplication::quit ()\fC [slot]\fR"Tells the application to exit with return code 0 (success). Equivalent to calling QApplication::exit( 0 )..PPIt'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..PPExample:.PP.nf.br QPushButton *quitButton = new QPushButton( "Quit" );.br connect( quitButton, SIGNAL(clicked()), qApp, SLOT(quit()) );.br.fi.PPSee also exit(), aboutToQuit(), lastWindowClosed(), and QAction..PPExamples:.)l addressbook/main.cpp, mdi/main.cpp, network/archivesearch/main.cpp, regexptester/main.cpp, t2/main.cpp, t4/main.cpp, and t6/main.cpp..SH "QWSDecoration & QApplication::qwsDecoration ()\fC [static]\fR"Return the QWSDecoration used for decorating windows..PPThis method is non-portable. It is available \fIonly\fR in Qt/Embedded..PPSee also QWSDecoration..SH "bool QApplication::qwsEventFilter ( QWSEvent * )\fC [virtual]\fR"This virtual function is only implemented under Qt/Embedded..PPIf you create an application that inherits QApplication and reimplement this function, you get direct access to all QWS (Q Window System) events that the are received from the QWS master process..PPReturn TRUE if you want to stop the event from being processed. Return FALSE for normal event dispatching..SH "void QApplication::qwsSetCustomColors ( QRgb * colorTable, int start, int numColors )"Set Qt/Embedded custom color table..PPQt/Embedded on 8-bpp displays allocates a standard 216 color cube. The remaining 40 colors may be used by setting a custom color table in the QWS master process before any clients connect..PP\fIcolorTable\fR is an array of up to 40 custom colors. \fIstart\fR is the starting index (0-39) and \fInumColors\fR is the number of colors to be set (1-40)..PPThis method is non-portable. It is available \fIonly\fR in Qt/Embedded..SH "void QApplication::qwsSetDecoration ( QWSDecoration * d )\fC [static]\fR"Set the QWSDecoration derived class to use for decorating the Qt/Embedded windows to \fId\fR..PPThis method is non-portable. It is available \fIonly\fR in Qt/Embedded..PPSee also QWSDecoration..SH "void QApplication::removeLibraryPath ( const QString & path )\fC [static]\fR"Removes \fIpath\fR from the library path list. If \fIpath\fR is empty or not in the path list, the list is not changed..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -