📄 qapplication.3qt
字号:
See also argc() and QApplication::QApplication()..SH "void QApplication::beep () \fC[static]\fR"Sounds the bell, using the default volume and sound..SH "QClipboard * QApplication::clipboard () \fC[static]\fR"Returns a pointer to the application global clipboard..SH "void QApplication::closeAllWindows () \fC[slot]\fR"A convenience function that closes all toplevel windows..PPThe function is particularly useful for applications with many toplevel windows. It could for example be connected to a "Quit" entry in the file menu as shown in the following code example:.PP.nf.br // the "Quit" menu entry should try to close all windows.br QPopupMenu* file = new QPopupMenu( this );.br file->insertItem( tr("&Quit"), qApp, SLOT(closeAllWindows()), CTRL+Key_Q );.br.br // when the last window was closed, the application should quit.br connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );.fi.PPThe windows are closed in random order, until one window does not accept the close event..PPSee also QWidget::close(), QWidget::closeEvent(), lastWindowClosed(), quit(), topLevelWidgets() and QWidget::isTopLevel()..SH "bool QApplication::closingDown () \fC[static]\fR"Returns TRUE if the application objects are being destroyed..PPSee also startingUp()..SH "int QApplication::colorSpec () \fC[static]\fR"Returns the color specification..PPSee also QApplication::setColorSpec()..SH "void QApplication::commitData ( QSessionManager & sm ) \fC[virtual]\fR"This function deals with session management. It is invoked when the QSessionManager wants the application to commit all its data..PPUsually this means saving of all open files, after getting permission from the user. Furthermore you may want to provide the user a way to cancel the shutdown..PPNote 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..PP\fBImportant\fR.brWithin this function, no user interaction is possible, \fIunless\fR you ask the session manager \fIsm\fR for explicit permission. See QSessionManager::allowsInteraction() and QSessionManager::allowsErrorInteraction() for details and example usage..PPThe default implementation requests interaction and sends a close event to all visible toplevel widgets. If at least one event was rejected, the shutdown is cancelled..PPSee also isSessionRestored(), sessionId() and saveState()..SH "int QApplication::cursorFlashTime () \fC[static]\fR"Returns the text cursor's flash time in milliseconds. The flash time is the time required to display, invert and restore the caret display..PPThe default value on X11 is 1000 milliseconds. On Windows, the control panel value is used..PPWidgets should not cache this value since it may vary any time the user changes the global desktop settings..PPSee also setCursorFlashTime()..SH "QTextCodec* QApplication::defaultCodec () const"Returns the default codec (see setDefaultCodec()). Returns 0 by default (no codec)..SH "QWidget * QApplication::desktop () \fC[static]\fR"Returns the desktop widget (also called the root window)..PPThe 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, as it works on some machines and not on others..PP.nf.br QWidget *d = QApplication::desktop();.br int w=d->width(); // returns screen width.br int h=d->height(); // returns screen height.fi.PPExamples:.(lhelpviewer/main.cpp scribble/main.cpp qmag/qmag.cpp.)l.SH "bool QApplication::desktopSettingsAware () \fC[static]\fR"Returns the value set by setDesktopSettingsAware(), by default TRUE..PPSee also setDesktopSettingsAware()..SH "int QApplication::doubleClickInterval () \fC[static]\fR"Returns the maximum duration for a double click..PPThe default value on X11 is 400 milliseconds. On Windows, the control panel value is used..PPSee also setDoubleClickInterval()..SH "int QApplication::enter_loop ()"This function enters the main event loop (recursively). Do not call it unless you really know what you are doing..PPSee also exit_loop() and loopLevel()..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 via 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 by using processEvents() and processOneEvent()..PPSee also quit(), exit(), processEvents() and setMainWidget()..PPExamples:.(lshowimg/main.cpp action/main.cpp rangecontrols/main.cpp iconview/main.cpp validator/main.cpp themes/main.cpp listviews/main.cpp aclock/main.cpp checklists/main.cpp drawlines/connect.cpp dclock/main.cpp mainlyQt/editor.cpp xform/xform.cpp application/main.cpp cursor/cursor.cpp layout/layout.cpp helpviewer/main.cpp buttongroups/main.cpp life/main.cpp i18n/main.cpp drawdemo/drawdemo.cpp lineedits/main.cpp popup/popup.cpp fileiconview/main.cpp listbox/main.cpp menu/menu.cpp progress/progress.cpp scribble/main.cpp qmag/qmag.cpp tabdialog/main.cpp splitter/splitter.cpp progressbar/main.cpp tooltip/main.cpp richtext/main.cpp qwerty/main.cpp forever/forever.cpp rot13/rot13.cpp xml/tagreader.)l-with-features/tagreader.cppscrollview/scrollview.cpp qfd/qfd.cpp addressbook/main.cpp movies/main.cpp picture/picture.cpp hello/main.cpp listboxcombo/main.cpp biff/main.cpp tictac/main.cpp customlayout/main.cpp mdi/main.cpp dirview/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, \fIretcode\fR 0 means success, any non-zero value indicates an error..PPNote that unlike the C library function of the same name, this function \fIdoes\fR returns to the caller - it is event processing that stops..PPSee also quit() and exec()..PPExamples:.(lpicture/picture.cpp.)l.SH "void QApplication::exit_loop ()"This function leaves from a recursive call to the main event loop. Do not call it unless you are an expert..PPSee also enter_loop() and loopLevel()..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()..SH "QWidget * QApplication::focusWidget () const"Returns the application widget that has the keyboard input focus, or null if no widget in this application has the focus..PPSee also QWidget::setFocus(), QWidget::hasFocus() and activeWindow()..SH "QFont QApplication::font ( const QWidget * w = 0 ) \fC[static]\fR"Returns the default font for a widget. Basically this function uses w->className() to get a font for it..PPIf \fIw\fR is 0 the default application font is returned..PPSee also setFont(), fontMetrics() and QWidget::font()..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 global strut of the application..PPSee also setGlobalStrut()..SH "void QApplication::guiThreadAwake () \fC[signal]\fR"This signal is emitted when the GUI threads is about to process a cycle of the event loop..PPSee also wakeUpGuiThread()..SH "bool QApplication::hasGlobalMouseTracking () \fC[static]\fR"Returns TRUE if global mouse tracking is enabled, otherwise FALSE..PPSee also setGlobalMouseTracking()..SH "void QApplication::installTranslator ( QTranslator * mf )"Adds \fImf\fR to the list of message files to be used for localization. Message files are searched starting with the most recently added file..PPSee also removeTranslator(), translate() and QObject::tr()..SH "bool QApplication::isEffectEnabled ( Qt::UIEffect effect ) \fC[static]\fR"Returns TRUE if \fIeffect\fR is enabled, otherwise FALSE..PPBy default, Qt will try to use the desktop settings, and setDesktopSettingsAware() must be called to prevent this..PPsa\\ setEffectEnabled(), Qt::UIEffect..SH "bool QApplication::isSessionRestored () const"Returns whether the application has been restored from an earlier session..PPSee also sessionId(), commitData() and saveState()..SH "void QApplication::lastWindowClosed () \fC[signal]\fR"This signal is emitted when the user has closed the last remaining 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, transient toplevel widgets such as popup menus and dialogs are omitted..PPSee also mainWidget(), topLevelWidgets(), QWidget::isTopLevel() and QWidget::close()..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() and locked()..SH "bool QApplication::locked ()"Returns TRUE if the Qt library mutex is locked by a different thread, otherwise returns FALSE..PP\fINOTE:\fR Due to differing implementations of recursive mutexes on various platforms, calling this function from the same thread that previous locked the mutex will return undefined results..PPSee also lock() and unlock()..SH "int QApplication::loopLevel () const"Returns the current loop level.PPSee also enter_loop() and exit_loop()..SH "QWidget * QApplication::mainWidget () const"Returns the main application widget, or a null pointer if there is not a defined main widget..PPSee also setMainWidget()..SH "bool QApplication::notify ( QObject * receiver, QEvent * event ) \fC[virtual]\fR"Sends \fIevent\fR to \fIreceiver:\fR \fCreceiver->event( event )\fR Returns the value that is returned from the receiver's event handler..PPReimplementing this virtual function is one of five ways to process an event: .IP 1Reimplementing this function. Very powerful, you get \fIcomplete\fR control, but of course only one subclass can be qApp..IP 2Installing an event filter on qApp. Such an event filter gets to process all events for all widgets, so it's just as powerful as reimplementing notify(), and in this way it's possible to have more than one application-global event filter. Global event filter get to see even mouse events for disabled widgets, and if global mouse tracking is enabled, mouse move events for all widgets..IP 3Reimplementing 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 4Installing an event filter on the object. Such an even filter gets all the events except Tab and Shift-Tab key presses..IP 5Finally, reimplementing paintEvent(), mousePressEvent() and so on. This is the normal, 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 a pointer to the default application palette. There is always an application palette, i.e. the returned pointer is guaranteed to be non-null..PPIf a widget is passed as argument, the default palette for the widget's class is returned. This may or may not be the application palett. In most cases there isn't be 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()..SH "void QApplication::polish ( QWidget * w ) \fC[virtual]\fR"Polishing of widgets..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 public functions of QWidget. Instead, based on meta information like QObject::className() you are able to customize any kind of widgets..PPSee also QStyle::polish(), QWidget::polish(), setPalette() and setFont()..SH "void QApplication::postEvent ( QObject * receiver, QEvent * event ) \fC[static]\fR"Stores the event in a queue and returns immediately..PPThe event must be allocated on the heap, as it is deleted when the event 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()..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 doing a long operation (e.g. copying a file)..PPSee also processOneEvent(), exec() and QTimer..SH "void QApplication::processEvents ( int maxtime )"Processes 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 processOneEvent(), exec() and QTimer..SH "void QApplication::processOneEvent ()"Waits 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 into existing program loops. Using 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 )..PPThis function is a slot, so you may connect any signal to activate quit()..PPExample:.PP.nf.br QPushButton *quitButton = new QPushButton( "Quit" );.br connect( quitButton, SIGNAL(clicked()), qApp, SLOT(quit()) );.fi.PPSee also exit() and aboutToQuit()..SH "void QApplication::removePostedEvents ( QObject * receiver ) \fC[static]\fR"Removes all events posted using postEvent() for \fIreceiver.\fR.PPThe events are \fInot\fR dispatched, simply removed from the queue. You should never need to call this function. If you do call it, be aware that killing events may cause \fIreceiver\fR to break one or more invariants..SH "void QApplication::removeTranslator ( QTranslator * mf )"Removes \fImf\fR from the list of message files used by this application. Does not, of course, delete mf..PPSee also installTranslator(), translate() and QObject::tr()..SH "void QApplication::restoreOverrideCursor () \fC[static]\fR"Undoes the last setOverrideCursor()..PPIf setOverrideCursor() has been called twice, calling restoreOverrideCursor() will activate the first cursor set. Calling this function a second time restores the original widgets cursors..PPSee also setOverrideCursor() and overrideCursor()..SH "void QApplication::saveState ( QSessionManager & sm ) \fC[virtual]\fR"This function deals with session management. It is invoked when the session manager wants the application to preserve its state for a future session..PPFor a text editor this would mean creating a temporary file that includes the current contents of the edit buffers, the location of the cursor and other aspects of the current editing session..PPNote 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..PP\fBImportant\fR.brWithin this function, no user interaction is possible, \fIunless\fR you ask the session manager \fIsm\fR for explicit permission. See QSessionManager::allowsInteraction() and QSessionManager::allowsErrorInteraction() for details..PPSee also isSessionRestored(), sessionId() and commitData()..SH "bool QApplication::sendEvent ( QObject * receiver, QEvent * event ) \fC[static]\fR"Sends an event directly to a receiver, using the notify() function. Returns the value that was returned from the event handler..PPSee also postEvent() and notify()..PPExamples:.(lpopup/popup.cpp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -