📄 qapplication.3qt
字号:
.br#endif.br QApplication app(argc, argv, useGUI);.br.br if ( useGUI ) {.br //start GUI version.br ....br } else {.br //start non-GUI version.br ....br }.br return app.exec();.br }.fi.SH "QApplication::QApplication ( int & argc, char ** argv, Type type )"Constructs an application object with \fIargc\fR command line arguments in \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..PP\fBWarning:\fR Qt only supports TrueColor visuals at depths higher than 8 bits-per-pixel..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..PP\fBWarning:\fR Qt only supports TrueColor visuals at depths higher than 8 bits-per-pixel..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 0..SH "void QApplication::aboutQt ()\fC [slot]\fR"Displays a simple message box about Qt. The message includes the version number of Qt being used by the application..PPThis is useful for inclusion in the Help menu of an application. See the examples/menu/menu.cpp example..PPThis function is a convenience slot for QMessageBox::aboutQt()..SH "void QApplication::aboutToQuit ()\fC [signal]\fR"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..PPThe signal is particularly useful if your application has to do some last-second cleanup. 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 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..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..PPThe default path list consists of a single entry, the installation directory for plugins. The default installation directory for plugins is \fCINSTALL/plugins\fR, where \fCINSTALL\fR is the directory where Qt was installed..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 \fCqwidgetlist.h\fR 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 "QString QApplication::applicationDirPath ()"Returns the directory that contains the application executable..PPFor example, if you have installed Qt in the \fCC:\Trolltech\Qt\fR directory, and you run the \fCdemo\fR example, this function will return "C:/Trolltech/Qt/examples/demo"..PPOn 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)..PP\fBWarning:\fR 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..PPSee also applicationFilePath()..SH "QString QApplication::applicationFilePath ()"Returns the file path of the application executable..PPFor example, if you have installed Qt in the \fCC:\Trolltech\Qt\fR directory, and you run the \fCdemo\fR example, this function will return "C:/Trolltech/Qt/examples/demo/demo.exe"..PP\fBWarning:\fR 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..PPSee also applicationDirPath()..SH "int QApplication::argc () const"Returns the number of command line arguments..PPThe documentation for argv() describes how to process command line arguments..PPSee also argv() and QApplication::QApplication()..PPExamples:.)l chart/main.cpp and 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"..PPQt provides a global pointer, \fCqApp\fR, that points to the QApplication object, and through which you can access argc() and argv() in functions other than main()..PPSee also argc() and QApplication::QApplication()..PPExamples:.)l chart/main.cpp and 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..PPExamples:.)l regexptester/regexptester.cpp and 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; otherwise returns FALSE..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\fBWarning:\fR Within 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 canceled..PPSee also isSessionRestored(), sessionId(), saveState(), and the Session Management overview..SH "int QApplication::cursorFlashTime ()\fC [static]\fR"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..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 be changed at any time by the user changing the global desktop settings..PPSee also setCursorFlashTime()..SH "QTextCodec * QApplication::defaultCodec () const"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PPReturns QTextCodec::codecForTr()..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, since this does not work on all operating systems..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 canvas/main.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 ()"\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code..PP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -