📄 qapplication.3qt
字号:
}.fi.SH "QApplication::QApplication ( int & argc, char ** argv, Type type )"Constructs an application object with the command line arguments \fIargc\fR and \fIargv\fR..PPFor Qt/Embedded, passing QApplication::GuiServer for \fItype\fR makes this application the server (equivalent to running with the -qws option)..SH "QApplication::QApplication ( Display * dpy, HANDLE visual = 0, HANDLE colormap = 0 )"Create an application, given an already open display \fIdpy\fR. If \fIvisual\fR and \fIcolormap\fR are non-zero, the application will use those as the default Visual and Colormap contexts..PPThis is available only on X11..SH "QApplication::QApplication ( Display * dpy, int argc, char ** argv, HANDLE visual = 0, HANDLE colormap = 0 )"Create an application, given an already open display \fIdpy\fR and using \fIargc\fR command line arguments in \fIargv\fR. If \fIvisual\fR and \fIcolormap\fR are non-zero, the application will use those as the default Visual and Colormap contexts..PPThis is available only on X11..SH "QApplication::~QApplication ()\fC [virtual]\fR"Cleans up any window system resources that were allocated by this application. Sets the global variable \fCqApp\fR to null..SH "void QApplication::aboutToQuit ()\fC [signal]\fR"This signal is emitted when the application is about to quit the main event loop. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session..PPThe signal is particularly useful if your application has to do some last-second cleanups. Note that no user interaction is possible in this state..PPSee also quit()..SH "QWidget * QApplication::activeModalWidget ()\fC [static]\fR"Returns the active modal widget..PPA 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..PPModal widgets are organized in a stack. This function returns the active modal widget at the top of the stack..PPSee also activePopupWidget() and topLevelWidgets()..SH "QWidget * QApplication::activePopupWidget ()\fC [static]\fR"Returns the active popup widget..PPA 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..PPOnly 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..PPSee also activeModalWidget() and topLevelWidgets()..SH "QWidget * QApplication::activeWindow () const"Returns the application top-level window that has the keyboard input focus, or null 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..PPSee also QWidget::setFocus(), QWidget::focus and focusWidget()..PPExample: network/mail/smtp.cpp..SH "void QApplication::addLibraryPath ( const QString & path )\fC [static]\fR"Append \fIpath\fR to the end of the library path list. If \fIpath\fR is empty or already in the path list, the path list is not changed..PPSee also removeLibraryPath(), libraryPaths() and setLibraryPaths()..SH "QWidgetList * QApplication::allWidgets ()\fC [static]\fR"Returns a list of all the widgets in the application..PPThe list is created using \fCnew\fR and must be deleted by the caller..PPThe list is empty (QPtrList::isEmpty()) if there are no widgets..PPNote that some of the widgets may be hidden..PPExample that updates all widgets:.PP.nf.br QWidgetList *list = QApplication::allWidgets();.br QWidgetListIt it( *list ); // iterate over the widgets.br QWidget * w;.br while ( (w=it.current()) != 0 ) { // for each widget....br ++it;.br w->update();.br }.br delete list; // delete the list, not the widgets.br.fi.PPThe QWidgetList class is defined in the qwidgetlist.h header file..PP\fBWarning:\fR 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..PPSee also topLevelWidgets(), QWidget::visible and QPtrList::isEmpty()..SH "QUuid QApplication::applicationId () const"Returns the application id that was set with setEnableRemoteControl..SH "int QApplication::argc () const"Returns the number of command line arguments..PPThe documentation for argv() contains a detailed description of how to process command line arguments..PPSee also argv() and QApplication::QApplication()..PPExample: scribble/scribble.cpp..SH "char ** QApplication::argv () const"Returns the command line argument vector..PP\fCargv()[0]\fR is the program name, \fCargv()[1]\fR is the first argument and \fCargv()[argc()-1]\fR is the last argument..PPA QApplication object is constructed by passing \fIargc\fR and \fIargv\fR from the \fCmain()\fR 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 \fC-display\fR, \fC-font\fR and a few more options..PPExample:.PP.nf.br // showargs.cpp - displays program arguments in a list box.br.br #include <qapplication.h>.br #include <qlistbox.h>.br.br int main( int argc, char **argv ).br {.br QApplication a( argc, argv );.br QListBox b;.br a.setMainWidget( &b );.br for ( int i=0; i<a.argc(); i++ ) // a.argc() == argc.br b.insertItem( a.argv()[i] ); // a.argv()[i] == argv[i].br b.show();.br return a.exec();.br }.br.fi.PPIf you run \fCshowargs -display unix:0 -font 9x15bold hello world\fR under X11, the list box contains the three strings" showargs", "hello" and "world"..PPSee also argc() and QApplication::QApplication()..PPExample: scribble/scribble.cpp..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..PPExample: showimg/showimg.cpp..SH "void QApplication::closeAllWindows ()\fC [slot]\fR"Closes all top-level windows..PPThis 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:.PP.nf.br // the "Quit" menu entry should try to close all windows.br QPopupMenu* file = new QPopupMenu( this );.br file->insertItem( "&Quit", qApp, SLOT(closeAllWindows()), CTRL+Key_Q );.br.br // when the last window is closed, the application should quit.br connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );.br.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..PPExamples:.)l action/application.cpp, application/application.cpp, helpviewer/helpwindow.cpp, mdi/application.cpp and qwerty/qwerty.cpp..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()..PPExample: showimg/showimg.cpp..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 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..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 top level widgets. If any 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 "QDesktopWidget * 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 operating systems and not on others..PP.nf.br QDesktopWidget *d = QApplication::desktop();.br int w=d->width(); // returns desktop width.br int h=d->height(); // returns desktop height.br.fi.PPExamples:.)l desktop/desktop.cpp, helpviewer/main.cpp, i18n/main.cpp, qmag/qmag.cpp, qwerty/main.cpp, qwerty/qwerty.cpp and scribble/main.cpp..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 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 action/actiongroup/main.cpp, biff/main.cpp, fonts/simple-qfont-demo/simple-qfont-demo.cpp, life/main.cpp, t1/main.cpp, t4/main.cpp and xml/outliner/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 return to the caller - it is event processing that stops..PPSee also quit() and exec()..PPExample: picture/picture.cpp..SH "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..PPSee also enter_loop() and loopLevel()..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 null 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. Basically this function uses w->className() to find the font..PPIf \fIw\fR is 0 the default application font is returned..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..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -