1QApplication(3qt) QApplication(3qt)
2
3
4
6 QApplication - Manages the GUI application's control flow and main
7 settings
8
10 #include <qapplication.h>
11
12 Inherits QObject.
13
14 Public Members
15 QApplication ( int & argc, char ** argv )
16 QApplication ( int & argc, char ** argv, bool GUIenabled )
17 enum Type { Tty, GuiClient, GuiServer }
18 QApplication ( int & argc, char ** argv, Type type )
19 QApplication ( Display * dpy, HANDLE visual = 0, HANDLE colormap = 0 )
20 QApplication ( Display * dpy, int argc, char ** argv, HANDLE visual =
21 0, HANDLE colormap = 0 )
22 virtual ~QApplication ()
23 int argc () const
24 char ** argv () const
25 Type type () const
26 enum ColorSpec { NormalColor = 0, CustomColor = 1, ManyColor = 2 }
27 QWidget * mainWidget () const
28 virtual void setMainWidget ( QWidget * mainWidget )
29 virtual void polish ( QWidget * w )
30 QWidget * focusWidget () const
31 QWidget * activeWindow () const
32 int exec ()
33 void processEvents ()
34 void processEvents ( int maxtime )
35 void processOneEvent () (obsolete)
36 bool hasPendingEvents ()
37 int enter_loop () (obsolete)
38 void exit_loop () (obsolete)
39 int loopLevel () const (obsolete)
40 virtual bool notify ( QObject * receiver, QEvent * e )
41 void setDefaultCodec ( QTextCodec * codec ) (obsolete)
42 QTextCodec * defaultCodec () const (obsolete)
43 void installTranslator ( QTranslator * mf )
44 void removeTranslator ( QTranslator * mf )
45 enum Encoding { DefaultCodec, UnicodeUTF8 }
46 QString translate ( const char * context, const char * sourceText,
47 const char * comment = 0, Encoding encoding = DefaultCodec ) const
48 QString applicationDirPath ()
49 QString applicationFilePath ()
50 virtual bool macEventFilter ( EventHandlerCallRef, EventRef )
51 virtual bool winEventFilter ( MSG * )
52 virtual bool x11EventFilter ( XEvent * )
53 int x11ProcessEvent ( XEvent * event )
54 virtual bool qwsEventFilter ( QWSEvent * )
55 void qwsSetCustomColors ( QRgb * colorTable, int start, int numColors )
56 void winFocus ( QWidget * widget, bool gotFocus )
57 bool isSessionRestored () const
58 QString sessionId () const
59 QString sessionKey () const
60 virtual void commitData ( QSessionManager & sm )
61 virtual void saveState ( QSessionManager & sm )
62 void wakeUpGuiThread ()
63 void lock ()
64 void unlock ( bool wakeUpGui = TRUE )
65 bool locked ()
66 bool tryLock ()
67
68 Public Slots
69 void quit ()
70 void closeAllWindows ()
71 void aboutQt ()
72
73 Signals
74 void lastWindowClosed ()
75 void aboutToQuit ()
76 void guiThreadAwake ()
77
78 Static Public Members
79 QStyle & style ()
80 void setStyle ( QStyle * style )
81 QStyle * setStyle ( const QString & style )
82 int colorSpec ()
83 void setColorSpec ( int spec )
84 QCursor * overrideCursor ()
85 void setOverrideCursor ( const QCursor & cursor, bool replace = FALSE )
86 void restoreOverrideCursor ()
87 bool hasGlobalMouseTracking ()
88 void setGlobalMouseTracking ( bool enable )
89 QPalette palette ( const QWidget * w = 0 )
90 void setPalette ( const QPalette & palette, bool informWidgets = FALSE,
91 const char * className = 0 )
92 QFont font ( const QWidget * w = 0 )
93 void setFont ( const QFont & font, bool informWidgets = FALSE, const
94 char * className = 0 )
95 QFontMetrics fontMetrics ()
96 QWidgetList * allWidgets ()
97 QWidgetList * topLevelWidgets ()
98 QDesktopWidget * desktop ()
99 QWidget * activePopupWidget ()
100 QWidget * activeModalWidget ()
101 QClipboard * clipboard ()
102 QWidget * widgetAt ( int x, int y, bool child = FALSE )
103 QWidget * widgetAt ( const QPoint & pos, bool child = FALSE )
104 QEventLoop * eventLoop ()
105 void exit ( int retcode = 0 )
106 bool sendEvent ( QObject * receiver, QEvent * event )
107 void postEvent ( QObject * receiver, QEvent * event )
108 void sendPostedEvents ( QObject * receiver, int event_type )
109 void sendPostedEvents ()
110 void removePostedEvents ( QObject * receiver )
111 bool startingUp ()
112 bool closingDown ()
113 void flushX ()
114 void flush ()
115 void syncX ()
116 void beep ()
117 void setWinStyleHighlightColor ( const QColor & c ) (obsolete)
118 const QColor & winStyleHighlightColor () (obsolete)
119 void setDesktopSettingsAware ( bool on )
120 bool desktopSettingsAware ()
121 void setCursorFlashTime ( int msecs )
122 int cursorFlashTime ()
123 void setDoubleClickInterval ( int ms )
124 int doubleClickInterval ()
125 void setWheelScrollLines ( int n )
126 int wheelScrollLines ()
127 void setGlobalStrut ( const QSize & strut )
128 QSize globalStrut ()
129 void setLibraryPaths ( const QStringList & paths )
130 QStringList libraryPaths ()
131 void addLibraryPath ( const QString & path )
132 void removeLibraryPath ( const QString & path )
133 void setStartDragTime ( int ms )
134 int startDragTime ()
135 void setStartDragDistance ( int l )
136 int startDragDistance ()
137 void setReverseLayout ( bool b )
138 bool reverseLayout ()
139 int horizontalAlignment ( int align )
140 bool isEffectEnabled ( Qt::UIEffect effect )
141 void setEffectEnabled ( Qt::UIEffect effect, bool enable = TRUE )
142 QWSDecoration & qwsDecoration ()
143 void qwsSetDecoration ( QWSDecoration * d )
144
146 void qAddPostRoutine ( QtCleanUpFunction p )
147 const char * qVersion ()
148 bool qSysInfo ( int * wordSize, bool * bigEndian )
149 void qDebug ( const char * msg, ... )
150 void qWarning ( const char * msg, ... )
151 void qFatal ( const char * msg, ... )
152 void qSystemWarning ( const char * msg, int code )
153 void Q_ASSERT ( bool test )
154 void Q_CHECK_PTR ( void * p )
155 QtMsgHandler qInstallMsgHandler ( QtMsgHandler h )
156
158 The QApplication class manages the GUI application's control flow and
159 main settings.
160
161 It contains the main event loop, where all events from the window
162 system and other sources are processed and dispatched. It also handles
163 the application's initialization and finalization, and provides session
164 management. It also handles most system-wide and application-wide
165 settings.
166
167 For any GUI application that uses Qt, there is precisely one
168 QApplication object, no matter whether the application has 0, 1, 2 or
169 more windows at any time.
170
171 The QApplication object is accessible through the global pointer qApp.
172 Its main areas of responsibility are:
173
174 It initializes the application with the user's desktop settings such as
175 palette(), font() and doubleClickInterval(). It keeps track of these
176 properties in case the user changes the desktop globally, for example
177 through some kind of control panel.
178
179 It performs event handling, meaning that it receives events from the
180 underlying window system and dispatches them to the relevant widgets.
181 By using sendEvent() and postEvent() you can send your own events to
182 widgets.
183
184 It parses common command line arguments and sets its internal state
185 accordingly. See the constructor documentation below for more details
186 about this.
187
188 It defines the application's look and feel, which is encapsulated in a
189 QStyle object. This can be changed at runtime with setStyle().
190
191 It specifies how the application is to allocate colors. See
192 setColorSpec() for details.
193
194 It provides localization of strings that are visible to the user via
195 translate().
196
197 It provides some magical objects like the desktop() and the
198 clipboard().
199
200 It knows about the application's windows. You can ask which widget is
201 at a certain position using widgetAt(), get a list of topLevelWidgets()
202 and closeAllWindows(), etc.
203
204 It manages the application's mouse cursor handling, see
205 setOverrideCursor() and setGlobalMouseTracking().
206
207 On the X window system, it provides functions to flush and sync the
208 communication stream, see flushX() and syncX().
209
210 It provides support for sophisticated session management. This makes it
211 possible for applications to terminate gracefully when the user logs
212 out, to cancel a shutdown process if termination isn't possible and
213 even to preserve the entire application's state for a future session.
214 See isSessionRestored(), sessionId() and commitData() and saveState()
215 for details.
216
217 The Application walk-through example contains a typical complete main()
218 that does the usual things with QApplication.
219
220 Since the QApplication object does so much initialization, it must be
221 created before any other objects related to the user interface are
222 created.
223
224 Since it also deals with common command line arguments, it is usually a
225 good idea to create it before any interpretation or modification of
226 argv is done in the application itself. (Note also that for X11,
227 setMainWidget() may change the main widget according to the -geometry
228 option. To preserve this functionality, you must set your defaults
229 before setMainWidget() and any overrides after.)
230
231 <center>.nf
232
233 </center>
234
235 Non-GUI programs: While Qt is not optimized or designed for writing
236 non-GUI programs, it's possible to use some of its classes without
237 creating a QApplication. This can be useful if you wish to share code
238 between a non-GUI server and a GUI client.
239
240 See also Main Window and Related Classes.
241
242 Member Type Documentation
244 QApplication::NormalColor - the default color allocation policy
245
246 QApplication::CustomColor - the same as NormalColor for X11; allocates
247 colors to a palette on demand under Windows
248
249 QApplication::ManyColor - the right choice for applications that use
250 thousands of colors
251
252 See setColorSpec() for full details.
253
255 This enum type defines the 8-bit encoding of character string arguments
256 to translate():
257
258 QApplication::DefaultCodec - the encoding specified by
259 QTextCodec::codecForTr() (Latin-1 if none has been set)
260
261 QApplication::UnicodeUTF8 - UTF-8
262
263 See also QObject::tr(), QObject::trUtf8(), and QString::fromUtf8().
264
266 QApplication::Tty - a console application
267
268 QApplication::GuiClient - a GUI client application
269
270 QApplication::GuiServer - a GUI server application
271
274 Initializes the window system and constructs an application object with
275 argc command line arguments in argv.
276
277 The global qApp pointer refers to this application object. Only one
278 application object should be created.
279
280 This application object must be constructed before any paint devices
281 (including widgets, pixmaps, bitmaps etc.).
282
283 Note that argc and argv might be changed. Qt removes command line
284 arguments that it recognizes. The modified argc and argv can also be
285 accessed later with qApp->argc() and qApp->argv(). The documentation
286 for argv() contains a detailed description of how to process command
287 line arguments.
288
289 Qt debugging options (not available if Qt was compiled with the
290 QT_NO_DEBUG flag defined):
291
292 -nograb, tells Qt that it must never grab the mouse or the keyboard.
293
294 -dograb (only under X11), running under a debugger can cause an
295 implicit -nograb, use -dograb to override.
296
297 -sync (only under X11), switches to synchronous mode for debugging.
298
299 See Debugging Techniques for a more detailed explanation.
300
301 All Qt programs automatically support the following command line
302 options:
303
304 -reverse causes text to be formatted for right-to-left languages rather
305 than in the usual left-to-right direction.
306
307 -style= style, sets the application GUI style. Possible values are
308 motif, windows, and platinum. If you compiled Qt with additional styles
309 or have additional styles as plugins these will be available to the
310 -style command line option.
311
312 -style style, is the same as listed above.
313
314 -session= session, restores the application from an earlier session.
315
316 -session session, is the same as listed above.
317
318 -widgetcount, prints debug message at the end about number of widgets
319 left undestroyed and maximum number of widgets existed at the same time
320
321 The X11 version of Qt also supports some traditional X11 command line
322 options:
323
324 -display display, sets the X display (default is $DISPLAY).
325
326 -geometry geometry, sets the client geometry of the main widget.
327
328 -fn or -font font, defines the application font. The font should be
329 specified using an X logical font description.
330
331 -bg or -background color, sets the default background color and an
332 application palette (light and dark shades are calculated).
333
334 -fg or -foreground color, sets the default foreground color.
335
336 -btn or -button color, sets the default button color.
337
338 -name name, sets the application name.
339
340 -title title, sets the application title (caption).
341
342 -visual TrueColor, forces the application to use a TrueColor visual on
343 an 8-bit display.
344
345 -ncols count, limits the number of colors allocated in the color cube
346 on an 8-bit display, if the application is using the
347 QApplication::ManyColor color specification. If count is 216 then a
348 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green, and 6 of
349 blue); for other values, a cube approximately proportional to a 2x3x1
350 cube is used.
351
352 -cmap, causes the application to install a private color map on an
353 8-bit display.
354
355 See also argc() and argv().
356
358 Constructs an application object with argc command line arguments in
359 argv. If GUIenabled is TRUE, a GUI application is constructed,
360 otherwise a non-GUI (console) application is created.
361
362 Set GUIenabled to FALSE for programs without a graphical user interface
363 that should be able to run without a window system.
364
365 On X11, the window system is initialized if GUIenabled is TRUE. If
366 GUIenabled is FALSE, the application does not connect to the X-server.
367 On Windows and Macintosh, currently the window system is always
368 initialized, regardless of the value of GUIenabled. This may change in
369 future versions of Qt.
370
371 The following example shows how to create an application that uses a
372 graphical interface when available.
373
374 int main( int argc, char **argv )
375 {
376 #ifdef Q_WS_X11
377 bool useGUI = getenv( "DISPLAY" ) != 0;
378 #else
379 bool useGUI = TRUE;
380 #endif
381 QApplication app(argc, argv, useGUI);
382 if ( useGUI ) {
383 //start GUI version
384 ...
385 } else {
386 //start non-GUI version
387 ...
388 }
389 return app.exec();
390 }
391
393 Constructs an application object with argc command line arguments in
394 argv.
395
396 For Qt/Embedded, passing QApplication::GuiServer for type makes this
397 application the server (equivalent to running with the -qws option).
398
400 = 0 )
401 Create an application, given an already open display dpy. If visual and
402 colormap are non-zero, the application will use those as the default
403 Visual and Colormap contexts.
404
405 Warning: Qt only supports TrueColor visuals at depths higher than 8
406 bits-per-pixel.
407
408 This is available only on X11.
409
411 visual = 0, HANDLE colormap = 0 )
412 Create an application, given an already open display dpy and using argc
413 command line arguments in argv. If visual and colormap are non-zero,
414 the application will use those as the default Visual and Colormap
415 contexts.
416
417 Warning: Qt only supports TrueColor visuals at depths higher than 8
418 bits-per-pixel.
419
420 This is available only on X11.
421
423 Cleans up any window system resources that were allocated by this
424 application. Sets the global variable qApp to 0.
425
427 Displays a simple message box about Qt. The message includes the
428 version number of Qt being used by the application.
429
430 This is useful for inclusion in the Help menu of an application. See
431 the examples/menu/menu.cpp example.
432
433 This function is a convenience slot for QMessageBox::aboutQt().
434
436 This signal is emitted when the application is about to quit the main
437 event loop, e.g. when the event loop level drops to zero. This may
438 happen either after a call to quit() from inside the application or
439 when the users shuts down the entire desktop session.
440
441 The signal is particularly useful if your application has to do some
442 last-second cleanup. Note that no user interaction is possible in this
443 state.
444
445 See also quit().
446
448 Returns the active modal widget.
449
450 A modal widget is a special top level widget which is a subclass of
451 QDialog that specifies the modal parameter of the constructor as TRUE.
452 A modal widget must be closed before the user can continue with other
453 parts of the program.
454
455 Modal widgets are organized in a stack. This function returns the
456 active modal widget at the top of the stack.
457
458 See also activePopupWidget() and topLevelWidgets().
459
461 Returns the active popup widget.
462
463 A popup widget is a special top level widget that sets the WType_Popup
464 widget flag, e.g. the QPopupMenu widget. When the application opens a
465 popup widget, all events are sent to the popup. Normal widgets and
466 modal widgets cannot be accessed before the popup widget is closed.
467
468 Only other popup widgets may be opened when a popup widget is shown.
469 The popup widgets are organized in a stack. This function returns the
470 active popup widget at the top of the stack.
471
472 See also activeModalWidget() and topLevelWidgets().
473
475 Returns the application top-level window that has the keyboard input
476 focus, or 0 if no application window has the focus. Note that there
477 might be an activeWindow() even if there is no focusWidget(), for
478 example if no widget in that window accepts key events.
479
480 See also QWidget::setFocus(), QWidget::focus, and focusWidget().
481
482 Example: network/mail/smtp.cpp.
483
485 Append path to the end of the library path list. If path is empty or
486 already in the path list, the path list is not changed.
487
488 The default path list consists of a single entry, the installation
489 directory for plugins. The default installation directory for plugins
490 is INSTALL/plugins, where INSTALL is the directory where Qt was
491 installed.
492
493 See also removeLibraryPath(), libraryPaths(), and setLibraryPaths().
494
496 Returns a list of all the widgets in the application.
497
498 The list is created using new and must be deleted by the caller.
499
500 The list is empty (QPtrList::isEmpty()) if there are no widgets.
501
502 Note that some of the widgets may be hidden.
503
504 Example that updates all widgets:
505
506 QWidgetList *list = QApplication::allWidgets();
507 QWidgetListIt it( *list ); // iterate over the widgets
508 QWidget * w;
509 while ( (w=it.current()) != 0 ) { // for each widget...
510 ++it;
511 w->update();
512 }
513 delete list; // delete the list, not the widgets
514
515 The QWidgetList class is defined in the qwidgetlist.h header file.
516
517 Warning: Delete the list as soon as you have finished using it. The
518 widgets in the list may be deleted by someone else at any time.
519
520 See also topLevelWidgets(), QWidget::visible, and QPtrList::isEmpty().
521
523 Returns the directory that contains the application executable.
524
525 For example, if you have installed Qt in the C:\Trolltech\Qt
526 directory, and you run the demo example, this function will return
527 "C:/Trolltech/Qt/examples/demo".
528
529 On Mac OS X this will point to the directory actually containing the
530 executable, which may be inside of an application bundle (if the
531 application is bundled).
532
533 Warning: On Unix, this function assumes that argv[0] contains the file
534 name of the executable (which it normally does). It also assumes that
535 the current directory hasn't been changed by the application.
536
537 See also applicationFilePath().
538
540 Returns the file path of the application executable.
541
542 For example, if you have installed Qt in the C:\Trolltech\Qt
543 directory, and you run the demo example, this function will return
544 "C:/Trolltech/Qt/examples/demo/demo.exe".
545
546 Warning: On Unix, this function assumes that argv[0] contains the file
547 name of the executable (which it normally does). It also assumes that
548 the current directory hasn't been changed by the application.
549
550 See also applicationDirPath().
551
553 Returns the number of command line arguments.
554
555 The documentation for argv() describes how to process command line
556 arguments.
557
558 See also argv() and QApplication::QApplication().
559
560 Examples:
561
563 Returns the command line argument vector.
564
565 argv()[0] is the program name, argv()[1] is the first argument and
566 argv()[argc()-1] is the last argument.
567
568 A QApplication object is constructed by passing argc and argv from the
569 main() function. Some of the arguments may be recognized as Qt options
570 and removed from the argument vector. For example, the X11 version of
571 Qt knows about -display, -font and a few more options.
572
573 Example:
574
575 // showargs.cpp - displays program arguments in a list box
576 #include <qapplication.h>
577 #include <qlistbox.h>
578 int main( int argc, char **argv )
579 {
580 QApplication a( argc, argv );
581 QListBox b;
582 a.setMainWidget( &b );
583 for ( int i = 0; i < a.argc(); i++ ) // a.argc() == argc
584 b.insertItem( a.argv()[i] ); // a.argv()[i] == argv[i]
585 b.show();
586 return a.exec();
587 }
588
589 If you run showargs -display unix:0 -font 9x15bold hello world under
590 X11, the list box contains the three strings "showargs"," hello" and
591 "world".
592
593 Qt provides a global pointer, qApp, that points to the QApplication
594 object, and through which you can access argc() and argv() in functions
595 other than main().
596
597 See also argc() and QApplication::QApplication().
598
599 Examples:
600
602 Sounds the bell, using the default volume and sound.
603
605 Returns a pointer to the application global clipboard.
606
607 Examples:
608
610 Closes all top-level windows.
611
612 This function is particularly useful for applications with many top-
613 level windows. It could, for example, be connected to a "Quit" entry in
614 the file menu as shown in the following code example:
615
616 // the "Quit" menu entry should try to close all windows
617 QPopupMenu* file = new QPopupMenu( this );
618 file->insertItem( "&Quit", qApp, SLOT(closeAllWindows()), CTRL+Key_Q );
619 // when the last window is closed, the application should quit
620 connect( qApp, SIGNAL( lastWindowClosed() ), qApp, SLOT( quit() ) );
621
622 The windows are closed in random order, until one window does not
623 accept the close event.
624
625 See also QWidget::close(), QWidget::closeEvent(), lastWindowClosed(),
626 quit(), topLevelWidgets(), and QWidget::isTopLevel.
627
628 Examples:
629
631 Returns TRUE if the application objects are being destroyed; otherwise
632 returns FALSE.
633
634 See also startingUp().
635
637 Returns the color specification.
638
639 See also QApplication::setColorSpec().
640
641 Example: showimg/showimg.cpp.
642
644 This function deals with session management. It is invoked when the
645 QSessionManager wants the application to commit all its data.
646
647 Usually this means saving all open files, after getting permission from
648 the user. Furthermore you may want to provide a means by which the user
649 can cancel the shutdown.
650
651 Note that you should not exit the application within this function.
652 Instead, the session manager may or may not do this afterwards,
653 depending on the context.
654
655 Warning: Within this function, no user interaction is possible, unless
656 you ask the session manager sm for explicit permission. See
657 QSessionManager::allowsInteraction() and
658 QSessionManager::allowsErrorInteraction() for details and example
659 usage.
660
661 The default implementation requests interaction and sends a close event
662 to all visible top level widgets. If any event was rejected, the
663 shutdown is canceled.
664
665 See also isSessionRestored(), sessionId(), saveState(), and the Session
666 Management overview.
667
669 Returns the text cursor's flash (blink) time in milliseconds. The flash
670 time is the time required to display, invert and restore the caret
671 display.
672
673 The default value on X11 is 1000 milliseconds. On Windows, the control
674 panel value is used.
675
676 Widgets should not cache this value since it may be changed at any time
677 by the user changing the global desktop settings.
678
679 See also setCursorFlashTime().
680
682 This function is obsolete. It is provided to keep old source working.
683 We strongly advise against using it in new code.
684
685 Returns QTextCodec::codecForTr().
686
688 Returns the desktop widget (also called the root window).
689
690 The desktop widget is useful for obtaining the size of the screen. It
691 may also be possible to draw on the desktop. We recommend against
692 assuming that it's possible to draw on the desktop, since this does not
693 work on all operating systems.
694
695 QDesktopWidget *d = QApplication::desktop();
696 int w = d->width(); // returns desktop width
697 int h = d->height(); // returns desktop height
698
699 Examples:
700
702 Returns the value set by setDesktopSettingsAware(); by default TRUE.
703
704 See also setDesktopSettingsAware().
705
707 Returns the maximum duration for a double click.
708
709 The default value on X11 is 400 milliseconds. On Windows, the control
710 panel value is used.
711
712 See also setDoubleClickInterval().
713
715 This function is obsolete. It is provided to keep old source working.
716 We strongly advise against using it in new code.
717
718 This function enters the main event loop (recursively). Do not call it
719 unless you really know what you are doing.
720
721 Use QApplication::eventLoop()->enterLoop() instead.
722
724 Returns the application event loop. This function will return zero if
725 called during and after destroying QApplication.
726
727 To create your own instance of QEventLoop or QEventLoop subclass create
728 it before you create the QApplication object.
729
730 See also QEventLoop.
731
732 Example: distributor/distributor.ui.h.
733
735 Enters the main event loop and waits until exit() is called or the main
736 widget is destroyed, and returns the value that was set to exit()
737 (which is 0 if exit() is called via quit()).
738
739 It is necessary to call this function to start event handling. The main
740 event loop receives events from the window system and dispatches these
741 to the application widgets.
742
743 Generally speaking, no user interaction can take place before calling
744 exec(). As a special case, modal widgets like QMessageBox can be used
745 before calling exec(), because modal widgets call exec() to start a
746 local event loop.
747
748 To make your application perform idle processing, i.e. executing a
749 special function whenever there are no pending events, use a QTimer
750 with 0 timeout. More advanced idle processing schemes can be achieved
751 using processEvents().
752
753 See also quit(), exit(), processEvents(), and setMainWidget().
754
755 Examples:
756
758 Tells the application to exit with a return code.
759
760 After this function has been called, the application leaves the main
761 event loop and returns from the call to exec(). The exec() function
762 returns retcode.
763
764 By convention, a retcode of 0 means success, and any non-zero value
765 indicates an error.
766
767 Note that unlike the C library function of the same name, this function
768 does return to the caller -- it is event processing that stops.
769
770 See also quit() and exec().
771
772 Examples:
773
775 This function is obsolete. It is provided to keep old source working.
776 We strongly advise against using it in new code.
777
778 This function exits from a recursive call to the main event loop. Do
779 not call it unless you are an expert.
780
781 Use QApplication::eventLoop()->exitLoop() instead.
782
784 Flushes the window system specific event queues.
785
786 If you are doing graphical changes inside a loop that does not return
787 to the event loop on asynchronous window systems like X11 or double
788 buffered window systems like MacOS X, and you want to visualize these
789 changes immediately (e.g. Splash Screens), call this function.
790
791 See also flushX(), sendPostedEvents(), and QPainter::flush().
792
794 Flushes the X event queue in the X11 implementation. This normally
795 returns almost immediately. Does nothing on other platforms.
796
797 See also syncX().
798
799 Example: xform/xform.cpp.
800
802 Returns the application widget that has the keyboard input focus, or 0
803 if no widget in this application has the focus.
804
805 See also QWidget::setFocus(), QWidget::focus, and activeWindow().
806
808 Returns the default font for the widget w, or the default application
809 font if w is 0.
810
811 See also setFont(), fontMetrics(), and QWidget::font.
812
813 Examples:
814
816 Returns display (screen) font metrics for the application font.
817
818 See also font(), setFont(), QWidget::fontMetrics(), and
819 QPainter::fontMetrics().
820
822 Returns the application's global strut.
823
824 The strut is a size object whose dimensions are the minimum that any
825 GUI element that the user can interact with should have. For example no
826 button should be resized to be smaller than the global strut size.
827
828 See also setGlobalStrut().
829
831 This signal is emitted after the event loop returns from a function
832 that could block.
833
834 See also wakeUpGuiThread().
835
837 Returns TRUE if global mouse tracking is enabled; otherwise returns
838 FALSE.
839
840 See also setGlobalMouseTracking().
841
843 This function returns TRUE if there are pending events; otherwise
844 returns FALSE. Pending events can be either from the window system or
845 posted events using QApplication::postEvent().
846
848 Strips out vertical alignment flags and transforms an alignment align
849 of AlignAuto into AlignLeft or AlignRight according to the language
850 used. The other horizontal alignment flags are left untouched.
851
853 Adds the message file mf to the list of message files to be used for
854 translations.
855
856 Multiple message files can be installed. Translations are searched for
857 in the last installed message file, then the one from last, and so on,
858 back to the first installed message file. The search stops as soon as a
859 matching translation is found.
860
861 See also removeTranslator(), translate(), and QTranslator::load().
862
863 Example: i18n/main.cpp.
864
866 Returns TRUE if effect is enabled; otherwise returns FALSE.
867
868 By default, Qt will try to use the desktop settings. Call
869 setDesktopSettingsAware(FALSE) to prevent this.
870
871 Note: All effects are disabled on screens running at less than 16-bit
872 color depth.
873
874 See also setEffectEnabled() and Qt::UIEffect.
875
877 Returns TRUE if the application has been restored from an earlier
878 session; otherwise returns FALSE.
879
880 See also sessionId(), commitData(), and saveState().
881
883 This signal is emitted when the user has closed the last top level
884 window.
885
886 The signal is very useful when your application has many top level
887 widgets but no main widget. You can then connect it to the quit() slot.
888
889 For convenience, this signal is not emitted for transient top level
890 widgets such as popup menus and dialogs.
891
892 See also mainWidget(), topLevelWidgets(), QWidget::isTopLevel, and
893 QWidget::close().
894
895 Examples:
896
898 Returns a list of paths that the application will search when
899 dynamically loading libraries. The installation directory for plugins
900 is the only entry if no paths have been set. The default installation
901 directory for plugins is INSTALL/plugins, where INSTALL is the
902 directory where Qt was installed. The directory of the application
903 executable (NOT the working directory) is also added to the plugin
904 paths.
905
906 If you want to iterate over the list, you should iterate over a copy,
907 e.g.
908
909 QStringList list = app.libraryPaths();
910 QStringList::Iterator it = list.begin();
911 while( it != list.end() ) {
912 myProcessing( *it );
913 ++it;
914 }
915
916 See the plugins documentation for a description of how the library
917 paths are used.
918
919 See also setLibraryPaths(), addLibraryPath(), removeLibraryPath(), and
920 QLibrary.
921
923 Lock the Qt Library Mutex. If another thread has already locked the
924 mutex, the calling thread will block until the other thread has
925 unlocked the mutex.
926
927 See also unlock(), locked(), and Thread Support in Qt.
928
930 Returns TRUE if the Qt Library Mutex is locked by a different thread;
931 otherwise returns FALSE.
932
933 Warning: Due to different implementations of recursive mutexes on the
934 supported platforms, calling this function from the same thread that
935 previously locked the mutex will give undefined results.
936
937 See also lock(), unlock(), and Thread Support in Qt.
938
940 This function is obsolete. It is provided to keep old source working.
941 We strongly advise against using it in new code.
942
943 Returns the current loop level.
944
945 Use QApplication::eventLoop()->loopLevel() instead.
946
948 This virtual function is only implemented under Macintosh.
949
950 If you create an application that inherits QApplication and reimplement
951 this function, you get direct access to all Carbon Events that are
952 received from the MacOS.
953
954 Return TRUE if you want to stop the event from being processed. Return
955 FALSE for normal event dispatching.
956
958 Returns the main application widget, or 0 if there is no main widget.
959
960 See also setMainWidget().
961
963 Sends event e to receiver: receiver->event(e). Returns the value that
964 is returned from the receiver's event handler.
965
966 For certain types of events (e.g. mouse and key events), the event will
967 be propagated to the receiver's parent and so on up to the top-level
968 object if the receiver is not interested in the event (i.e., it returns
969 FALSE).
970
971 There are five different ways that events can be processed;
972 reimplementing this virtual function is just one of them. All five
973 approaches are listed below: <ol type=1>
974
975 Reimplementing this function. This is very powerful, providing complete
976 control; but only one subclass can be qApp.
977
978 Installing an event filter on qApp. Such an event filter is able to
979 process all events for all widgets, so it's just as powerful as
980 reimplementing notify(); furthermore, it's possible to have more than
981 one application-global event filter. Global event filters even see
982 mouse events for disabled widgets, and if global mouse tracking is
983 enabled, as well as mouse move events for all widgets.
984
985 Reimplementing QObject::event() (as QWidget does). If you do this you
986 get Tab key presses, and you get to see the events before any widget-
987 specific event filters.
988
989 Installing an event filter on the object. Such an event filter gets all
990 the events except Tab and Shift-Tab key presses.
991
992 Reimplementing paintEvent(), mousePressEvent() and so on. This is the
993 commonest, easiest and least powerful way.
994
995 See also QObject::event() and installEventFilter().
996
998 Returns the active application override cursor.
999
1000 This function returns 0 if no application cursor has been defined (i.e.
1001 the internal cursor stack is empty).
1002
1003 See also setOverrideCursor() and restoreOverrideCursor().
1004
1006 Returns the application palette.
1007
1008 If a widget is passed in w, the default palette for the widget's class
1009 is returned. This may or may not be the application palette. In most
1010 cases there isn't a special palette for certain types of widgets, but
1011 one notable exception is the popup menu under Windows, if the user has
1012 defined a special background color for menus in the display settings.
1013
1014 See also setPalette() and QWidget::palette.
1015
1016 Examples:
1017
1019 Initialization of the appearance of the widget w before it is first
1020 shown.
1021
1022 Usually widgets call this automatically when they are polished. It may
1023 be used to do some style-based central customization of widgets.
1024
1025 Note that you are not limited to the public functions of QWidget.
1026 Instead, based on meta information like QObject::className() you are
1027 able to customize any kind of widget.
1028
1029 See also QStyle::polish(), QWidget::polish(), setPalette(), and
1030 setFont().
1031
1033 Note: This function is thread-safe when Qt is built withthread
1034 support.</p> Adds the event event with the object receiver as the
1035 receiver of the event, to an event queue and returns immediately.
1036
1037 The event must be allocated on the heap since the post event queue will
1038 take ownership of the event and delete it once it has been posted.
1039
1040 When control returns to the main event loop, all events that are stored
1041 in the queue will be sent using the notify() function.
1042
1043 See also sendEvent() and notify().
1044
1046 Processes pending events, for 3 seconds or until there are no more
1047 events to process, whichever is shorter.
1048
1049 You can call this function occasionally when your program is busy
1050 performing a long operation (e.g. copying a file).
1051
1052 See also exec(), QTimer, and QEventLoop::processEvents().
1053
1054 Examples:
1055
1057 This is an overloaded member function, provided for convenience. It
1058 behaves essentially like the above function.
1059
1060 Processes pending events for maxtime milliseconds or until there are no
1061 more events to process, whichever is shorter.
1062
1063 You can call this function occasionally when you program is busy doing
1064 a long operation (e.g. copying a file).
1065
1066 See also exec(), QTimer, and QEventLoop::processEvents().
1067
1069 This function is obsolete. It is provided to keep old source working.
1070 We strongly advise against using it in new code.
1071
1072 Waits for an event to occur, processes it, then returns.
1073
1074 This function is useful for adapting Qt to situations where the event
1075 processing must be grafted onto existing program loops.
1076
1077 Using this function in new applications may be an indication of design
1078 problems.
1079
1080 See also processEvents(), exec(), and QTimer.
1081
1083 Tells the application to exit with return code 0 (success). Equivalent
1084 to calling QApplication::exit( 0 ).
1085
1086 It's common to connect the lastWindowClosed() signal to quit(), and you
1087 also often connect e.g. QButton::clicked() or signals in QAction,
1088 QPopupMenu or QMenuBar to it.
1089
1090 Example:
1091
1092 QPushButton *quitButton = new QPushButton( "Quit" );
1093 connect( quitButton, SIGNAL(clicked()), qApp, SLOT(quit()) );
1094
1095 See also exit(), aboutToQuit(), lastWindowClosed(), and QAction.
1096
1097 Examples:
1098
1100 Return the QWSDecoration used for decorating windows.
1101
1102 This method is non-portable. It is available only in Qt/Embedded.
1103
1104 See also QWSDecoration.
1105
1107 This virtual function is only implemented under Qt/Embedded.
1108
1109 If you create an application that inherits QApplication and reimplement
1110 this function, you get direct access to all QWS (Q Window System)
1111 events that the are received from the QWS master process.
1112
1113 Return TRUE if you want to stop the event from being processed. Return
1114 FALSE for normal event dispatching.
1115
1117 numColors )
1118 Set Qt/Embedded custom color table.
1119
1120 Qt/Embedded on 8-bpp displays allocates a standard 216 color cube. The
1121 remaining 40 colors may be used by setting a custom color table in the
1122 QWS master process before any clients connect.
1123
1124 colorTable is an array of up to 40 custom colors. start is the starting
1125 index (0-39) and numColors is the number of colors to be set (1-40).
1126
1127 This method is non-portable. It is available only in Qt/Embedded.
1128
1130 Set the QWSDecoration derived class to use for decorating the
1131 Qt/Embedded windows to d.
1132
1133 This method is non-portable. It is available only in Qt/Embedded.
1134
1135 See also QWSDecoration.
1136
1138 Removes path from the library path list. If path is empty or not in the
1139 path list, the list is not changed.
1140
1141 See also addLibraryPath(), libraryPaths(), and setLibraryPaths().
1142
1144 Note: This function is thread-safe when Qt is built withthread
1145 support.</p> Removes all events posted using postEvent() for receiver.
1146
1147 The events are not dispatched, instead they are removed from the queue.
1148 You should never need to call this function. If you do call it, be
1149 aware that killing events may cause receiver to break one or more
1150 invariants.
1151
1153 Removes the message file mf from the list of message files used by this
1154 application. (It does not delete the message file from the file
1155 system.)
1156
1157 See also installTranslator(), translate(), and QObject::tr().
1158
1159 Example: i18n/main.cpp.
1160
1162 Undoes the last setOverrideCursor().
1163
1164 If setOverrideCursor() has been called twice, calling
1165 restoreOverrideCursor() will activate the first cursor set. Calling
1166 this function a second time restores the original widgets' cursors.
1167
1168 See also setOverrideCursor() and overrideCursor().
1169
1170 Examples:
1171
1173 Returns TRUE if all dialogs and widgets will be laid out in a mirrored
1174 (right to left) fashion. Returns FALSE if dialogs and widgets will be
1175 laid out left to right.
1176
1177 See also setReverseLayout().
1178
1180 This function deals with session management. It is invoked when the
1181 session manager wants the application to preserve its state for a
1182 future session.
1183
1184 For example, a text editor would create a temporary file that includes
1185 the current contents of its edit buffers, the location of the cursor
1186 and other aspects of the current editing session.
1187
1188 Note that you should never exit the application within this function.
1189 Instead, the session manager may or may not do this afterwards,
1190 depending on the context. Futhermore, most session managers will very
1191 likely request a saved state immediately after the application has been
1192 started. This permits the session manager to learn about the
1193 application's restart policy.
1194
1195 Warning: Within this function, no user interaction is possible, unless
1196 you ask the session manager sm for explicit permission. See
1197 QSessionManager::allowsInteraction() and
1198 QSessionManager::allowsErrorInteraction() for details.
1199
1200 See also isSessionRestored(), sessionId(), commitData(), and the
1201 Session Management overview.
1202
1204 Sends event event directly to receiver receiver, using the notify()
1205 function. Returns the value that was returned from the event handler.
1206
1207 The event is not deleted when the event has been sent. The normal
1208 approach is to create the event on the stack, e.g.
1209
1210 QMouseEvent me( QEvent::MouseButtonPress, pos, 0, 0 );
1211 QApplication::sendEvent( mainWindow, &me );
1212 If you create the event on the heap you must delete it.
1213
1214 See also postEvent() and notify().
1215
1216 Example: popup/popup.cpp.
1217
1219 [static]
1220 Immediately dispatches all events which have been previously queued
1221 with QApplication::postEvent() and which are for the object receiver
1222 and have the event type event_type.
1223
1224 Note that events from the window system are not dispatched by this
1225 function, but by processEvents().
1226
1227 If receiver is null, the events of event_type are sent for all objects.
1228 If event_type is 0, all the events are sent for receiver.
1229
1231 This is an overloaded member function, provided for convenience. It
1232 behaves essentially like the above function.
1233
1234 Dispatches all posted events, i.e. empties the event queue.
1235
1237 Returns the current session's identifier.
1238
1239 If the application has been restored from an earlier session, this
1240 identifier is the same as it was in that previous session.
1241
1242 The session identifier is guaranteed to be unique both for different
1243 applications and for different instances of the same application.
1244
1245 See also isSessionRestored(), sessionKey(), commitData(), and
1246 saveState().
1247
1249 Returns the session key in the current session.
1250
1251 If the application has been restored from an earlier session, this key
1252 is the same as it was when the previous session ended.
1253
1254 The session key changes with every call of commitData() or saveState().
1255
1256 See also isSessionRestored(), sessionId(), commitData(), and
1257 saveState().
1258
1260 Sets the color specification for the application to spec.
1261
1262 The color specification controls how the application allocates colors
1263 when run on a display with a limited amount of colors, e.g. 8 bit / 256
1264 color displays.
1265
1266 The color specification must be set before you create the QApplication
1267 object.
1268
1269 The options are:
1270
1271 QApplication::NormalColor. This is the default color allocation
1272 strategy. Use this option if your application uses buttons, menus,
1273 texts and pixmaps with few colors. With this option, the application
1274 uses system global colors. This works fine for most applications under
1275 X11, but on Windows machines it may cause dithering of non-standard
1276 colors.
1277
1278 QApplication::CustomColor. Use this option if your application needs a
1279 small number of custom colors. On X11, this option is the same as
1280 NormalColor. On Windows, Qt creates a Windows palette, and allocates
1281 colors to it on demand.
1282
1283 QApplication::ManyColor. Use this option if your application is very
1284 color hungry (e.g. it requires thousands of colors). Under X11 the
1285 effect is:
1286
1287 For 256-color displays which have at best a 256 color true color
1288 visual, the default visual is used, and colors are allocated from a
1289 color cube. The color cube is the 6x6x6 (216 color) "Web
1290 palette"<sup>*</sup>, but the number of colors can be changed by the
1291 -ncols option. The user can force the application to use the true color
1292 visual with the -visual option.
1293
1294 For 256-color displays which have a true color visual with more than
1295 256 colors, use that visual. Silicon Graphics X servers have this
1296 feature, for example. They provide an 8 bit visual by default but can
1297 deliver true color when asked. On Windows, Qt creates a Windows
1298 palette, and fills it with a color cube.
1299
1300 Be aware that the CustomColor and ManyColor choices may lead to
1301 colormap flashing: The foreground application gets (most) of the
1302 available colors, while the background windows will look less
1303 attractive.
1304
1305 Example:
1306
1307 int main( int argc, char **argv )
1308 {
1309 QApplication::setColorSpec( QApplication::ManyColor );
1310 QApplication a( argc, argv );
1311 ...
1312 }
1313
1314 QColor provides more functionality for controlling color allocation and
1315 freeing up certain colors. See QColor::enterAllocContext() for more
1316 information.
1317
1318 To check what mode you end up with, call QColor::numBitPlanes() once
1319 the QApplication object exists. A value greater than 8 (typically 16,
1320 24 or 32) means true color.
1321
1322 <sup>*</sup> The color cube used by Qt has 216 colors whose red, green,
1323 and blue components always have one of the following values: 0x00,
1324 0x33, 0x66, 0x99, 0xCC, or 0xFF.
1325
1326 See also colorSpec(), QColor::numBitPlanes(), and
1327 QColor::enterAllocContext().
1328
1329 Examples:
1330
1332 Sets the text cursor's flash (blink) time to msecs milliseconds. The
1333 flash time is the time required to display, invert and restore the
1334 caret display. Usually the text cursor is displayed for msecs/2
1335 milliseconds, then hidden for msecs/2 milliseconds, but this may vary.
1336
1337 Note that on Microsoft Windows, calling this function sets the cursor
1338 flash time for all windows.
1339
1340 See also cursorFlashTime().
1341
1343 This function is obsolete. It is provided to keep old source working.
1344 We strongly advise against using it in new code.
1345
1346 This is the same as QTextCodec::setCodecForTr().
1347
1349 By default, Qt will try to use the current standard colors, fonts etc.,
1350 from the underlying window system's desktop settings, and use them for
1351 all relevant widgets. This behavior can be switched off by calling this
1352 function with on set to FALSE.
1353
1354 This static function must be called before creating the QApplication
1355 object, like this:
1356
1357 int main( int argc, char** argv ) {
1358 QApplication::setDesktopSettingsAware( FALSE ); // I know better than the user
1359 QApplication myApp( argc, argv ); // Use default fonts & colors
1360 ...
1361 }
1362
1363 See also desktopSettingsAware().
1364
1366 Sets the time limit that distinguishes a double click from two
1367 consecutive mouse clicks to ms milliseconds.
1368
1369 Note that on Microsoft Windows, calling this function sets the double
1370 click interval for all windows.
1371
1372 See also doubleClickInterval().
1373
1375 ) [static]
1376 Enables the UI effect effect if enable is TRUE, otherwise the effect
1377 will not be used.
1378
1379 Note: All effects are disabled on screens running at less than 16-bit
1380 color depth.
1381
1382 See also isEffectEnabled(), Qt::UIEffect, and
1383 setDesktopSettingsAware().
1384
1386 const char * className = 0 ) [static]
1387 Changes the default application font to font. If informWidgets is TRUE,
1388 then existing widgets are informed about the change and may adjust
1389 themselves to the new application setting. If informWidgets is FALSE,
1390 the change only affects newly created widgets. If className is passed,
1391 the change applies only to classes that inherit className (as reported
1392 by QObject::inherits()).
1393
1394 On application start-up, the default font depends on the window system.
1395 It can vary depending on both the window system version and the locale.
1396 This function lets you override the default font; but overriding may be
1397 a bad idea because, for example, some locales need extra-large fonts to
1398 support their special characters.
1399
1400 See also font(), fontMetrics(), and QWidget::font.
1401
1402 Examples:
1403
1405 Enables global mouse tracking if enable is TRUE, or disables it if
1406 enable is FALSE.
1407
1408 Enabling global mouse tracking makes it possible for widget event
1409 filters or application event filters to get all mouse move events, even
1410 when no button is depressed. This is useful for special GUI elements,
1411 e.g. tooltips.
1412
1413 Global mouse tracking does not affect widgets and their
1414 mouseMoveEvent(). For a widget to get mouse move events when no button
1415 is depressed, it must do QWidget::setMouseTracking(TRUE).
1416
1417 This function uses an internal counter. Each
1418 setGlobalMouseTracking(TRUE) must have a corresponding
1419 setGlobalMouseTracking(FALSE):
1420
1421 // at this point global mouse tracking is off
1422 QApplication::setGlobalMouseTracking( TRUE );
1423 QApplication::setGlobalMouseTracking( TRUE );
1424 QApplication::setGlobalMouseTracking( FALSE );
1425 // at this point it's still on
1426 QApplication::setGlobalMouseTracking( FALSE );
1427 // but now it's off
1428
1429 See also hasGlobalMouseTracking() and QWidget::mouseTracking.
1430
1432 Sets the application's global strut to strut.
1433
1434 The strut is a size object whose dimensions are the minimum that any
1435 GUI element that the user can interact with should have. For example no
1436 button should be resized to be smaller than the global strut size.
1437
1438 The strut size should be considered when reimplementing GUI controls
1439 that may be used on touch-screens or similar IO-devices.
1440
1441 Example:
1442
1443 QSize& WidgetClass::sizeHint() const
1444 {
1445 return QSize( 80, 25 ).expandedTo( QApplication::globalStrut() );
1446 }
1447
1448 See also globalStrut().
1449
1451 Sets the list of directories to search when loading libraries to paths.
1452 All existing paths will be deleted and the path list will consist of
1453 the paths given in paths.
1454
1455 See also libraryPaths(), addLibraryPath(), removeLibraryPath(), and
1456 QLibrary.
1457
1459 Sets the application's main widget to mainWidget.
1460
1461 In most respects the main widget is like any other widget, except that
1462 if it is closed, the application exits. Note that QApplication does not
1463 take ownership of the mainWidget, so if you create your main widget on
1464 the heap you must delete it yourself.
1465
1466 You need not have a main widget; connecting lastWindowClosed() to
1467 quit() is an alternative.
1468
1469 For X11, this function also resizes and moves the main widget according
1470 to the -geometry command-line option, so you should set the default
1471 geometry (using QWidget::setGeometry()) before calling setMainWidget().
1472
1473 See also mainWidget(), exec(), and quit().
1474
1475 Examples:
1476
1478 FALSE ) [static]
1479 Sets the application override cursor to cursor.
1480
1481 Application override cursors are intended for showing the user that the
1482 application is in a special state, for example during an operation that
1483 might take some time.
1484
1485 This cursor will be displayed in all the application's widgets until
1486 restoreOverrideCursor() or another setOverrideCursor() is called.
1487
1488 Application cursors are stored on an internal stack.
1489 setOverrideCursor() pushes the cursor onto the stack, and
1490 restoreOverrideCursor() pops the active cursor off the stack. Every
1491 setOverrideCursor() must eventually be followed by a corresponding
1492 restoreOverrideCursor(), otherwise the stack will never be emptied.
1493
1494 If replace is TRUE, the new cursor will replace the last override
1495 cursor (the stack keeps its depth). If replace is FALSE, the new stack
1496 is pushed onto the top of the stack.
1497
1498 Example:
1499
1500 QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
1501 calculateHugeMandelbrot(); // lunch time...
1502 QApplication::restoreOverrideCursor();
1503
1504 See also overrideCursor(), restoreOverrideCursor(), and
1505 QWidget::cursor.
1506
1507 Examples:
1508
1510 FALSE, const char * className = 0 ) [static]
1511 Changes the default application palette to palette. If informWidgets is
1512 TRUE, then existing widgets are informed about the change and may
1513 adjust themselves to the new application setting. If informWidgets is
1514 FALSE, the change only affects newly created widgets.
1515
1516 If className is passed, the change applies only to widgets that inherit
1517 className (as reported by QObject::inherits()). If className is left 0,
1518 the change affects all widgets, thus overriding any previously set
1519 class specific palettes.
1520
1521 The palette may be changed according to the current GUI style in
1522 QStyle::polish().
1523
1524 See also QWidget::palette, palette(), and QStyle::polish().
1525
1526 Examples:
1527
1529 If b is TRUE, all dialogs and widgets will be laid out in a mirrored
1530 fashion, as required by right to left languages such as Arabic and
1531 Hebrew. If b is FALSE, dialogs and widgets are laid out left to right.
1532
1533 Changing this flag in runtime does not cause a relayout of already
1534 instantiated widgets.
1535
1536 See also reverseLayout().
1537
1539 Sets the distance after which a drag should start to l pixels.
1540
1541 See also startDragDistance().
1542
1544 Sets the time after which a drag should start to ms ms.
1545
1546 See also startDragTime().
1547
1549 Sets the application's GUI style to style. Ownership of the style
1550 object is transferred to QApplication, so QApplication will delete the
1551 style object on application exit or when a new style is set.
1552
1553 Example usage:
1554
1555 QApplication::setStyle( new QWindowsStyle );
1556
1557 When switching application styles, the color palette is set back to the
1558 initial colors or the system defaults. This is necessary since certain
1559 styles have to adapt the color palette to be fully style-guide
1560 compliant.
1561
1562 See also style(), QStyle, setPalette(), and desktopSettingsAware().
1563
1564 Example: themes/themes.cpp.
1565
1567 This is an overloaded member function, provided for convenience. It
1568 behaves essentially like the above function.
1569
1570 Requests a QStyle object for style from the QStyleFactory.
1571
1572 The string must be one of the QStyleFactory::keys(), typically one of
1573 "windows", "motif", "cde", "motifplus", "platinum", "sgi" and"
1574 compact". Depending on the platform, "windowsxp", "aqua" or" macintosh"
1575 may be available.
1576
1577 A later call to the QApplication constructor will override the
1578 requested style when a "-style" option is passed in as a commandline
1579 parameter.
1580
1581 Returns 0 if an unknown style is passed, otherwise the QStyle object
1582 returned is set as the application's GUI style.
1583
1585 Sets the number of lines to scroll when the mouse wheel is rotated to
1586 n.
1587
1588 If this number exceeds the number of visible lines in a certain widget,
1589 the widget should interpret the scroll operation as a single page up /
1590 page down operation instead.
1591
1592 See also wheelScrollLines().
1593
1595 This function is obsolete. It is provided to keep old source working.
1596 We strongly advise against using it in new code.
1597
1598 Sets the color used to mark selections in windows style for all widgets
1599 in the application. Will repaint all widgets if the color is changed.
1600
1601 The default color is darkBlue.
1602
1603 See also winStyleHighlightColor().
1604
1606 If you support drag and drop in you application and a drag should start
1607 after a mouse click and after moving the mouse a certain distance, you
1608 should use the value which this method returns as the distance.
1609
1610 For example, if the mouse position of the click is stored in startPos
1611 and the current position (e.g. in the mouse move event) is currPos, you
1612 can find out if a drag should be started with code like this:
1613
1614 if ( ( startPos - currPos ).manhattanLength() >
1615 QApplication::startDragDistance() )
1616 startTheDrag();
1617
1618 Qt uses this value internally, e.g. in QFileDialog.
1619
1620 The default value is 4 pixels.
1621
1622 See also setStartDragDistance(), startDragTime(), and
1623 QPoint::manhattanLength().
1624
1626 If you support drag and drop in you application and a drag should start
1627 after a mouse click and after a certain time elapsed, you should use
1628 the value which this method returns as the delay (in ms).
1629
1630 Qt also uses this delay internally, e.g. in QTextEdit and QLineEdit,
1631 for starting a drag.
1632
1633 The default value is 500 ms.
1634
1635 See also setStartDragTime() and startDragDistance().
1636
1638 Returns TRUE if an application object has not been created yet;
1639 otherwise returns FALSE.
1640
1641 See also closingDown().
1642
1644 Returns the application's style object.
1645
1646 See also setStyle() and QStyle.
1647
1649 Synchronizes with the X server in the X11 implementation. This normally
1650 takes some time. Does nothing on other platforms.
1651
1652 See also flushX().
1653
1655 Returns a list of the top level widgets in the application.
1656
1657 The list is created using new and must be deleted by the caller.
1658
1659 The list is empty (QPtrList::isEmpty()) if there are no top level
1660 widgets.
1661
1662 Note that some of the top level widgets may be hidden, for example the
1663 tooltip if no tooltip is currently shown.
1664
1665 Example:
1666
1667 // Show all hidden top level widgets.
1668 QWidgetList *list = QApplication::topLevelWidgets();
1669 QWidgetListIt it( *list ); // iterate over the widgets
1670 QWidget * w;
1671 while ( (w=it.current()) != 0 ) { // for each top level widget...
1672 ++it;
1673 if ( !w->isVisible() )
1674 w->show();
1675 }
1676 delete list; // delete the list, not the widgets
1677
1678 Warning: Delete the list as soon you have finished using it. The
1679 widgets in the list may be deleted by someone else at any time.
1680
1681 See also allWidgets(), QWidget::isTopLevel, QWidget::visible, and
1682 QPtrList::isEmpty().
1683
1685 sourceText, const char * comment = 0, Encoding encoding = DefaultCodec
1686 ) const
1687 Note: This function is reentrant when Qt is built with thread
1688 support.</p> Returns the translation text for sourceText, by querying
1689 the installed messages files. The message files are searched from the
1690 most recently installed message file back to the first installed
1691 message file.
1692
1693 QObject::tr() and QObject::trUtf8() provide this functionality more
1694 conveniently.
1695
1696 context is typically a class name (e.g., "MyDialog") and sourceText is
1697 either English text or a short identifying text, if the output text
1698 will be very long (as for help texts).
1699
1700 comment is a disambiguating comment, for when the same sourceText is
1701 used in different roles within the same context. By default, it is
1702 null. encoding indicates the 8-bit encoding of character stings
1703
1704 See the QTranslator documentation for more information about contexts
1705 and comments.
1706
1707 If none of the message files contain a translation for sourceText in
1708 context, this function returns a QString equivalent of sourceText. The
1709 encoding of sourceText is specified by encoding; it defaults to
1710 DefaultCodec.
1711
1712 This function is not virtual. You can use alternative translation
1713 techniques by subclassing QTranslator.
1714
1715 Warning: This method is reentrant only if all translators are installed
1716 before calling this method. Installing or removing translators while
1717 performing translations is not supported. Doing so will most likely
1718 result in crashes or other undesirable behavior.
1719
1720 See also QObject::tr(), installTranslator(), and defaultCodec().
1721
1723 Attempts to lock the Qt Library Mutex, and returns immediately. If the
1724 lock was obtained, this function returns TRUE. If another thread has
1725 locked the mutex, this function returns FALSE, instead of waiting for
1726 the lock to become available.
1727
1728 The mutex must be unlocked with unlock() before another thread can
1729 successfully lock it.
1730
1731 See also lock(), unlock(), and Thread Support in Qt.
1732
1734 Returns the type of application, Tty, GuiClient or GuiServer.
1735
1737 Unlock the Qt Library Mutex. If wakeUpGui is TRUE (the default), then
1738 the GUI thread will be woken with QApplication::wakeUpGuiThread().
1739
1740 See also lock(), locked(), and Thread Support in Qt.
1741
1743 Wakes up the GUI thread.
1744
1745 See also guiThreadAwake() and Thread Support in Qt.
1746
1748 Returns the number of lines to scroll when the mouse wheel is rotated.
1749
1750 See also setWheelScrollLines().
1751
1753
1754 Returns a pointer to the widget at global screen position (x, y), or 0
1755 if there is no Qt widget there.
1756
1757 If child is FALSE and there is a child widget at position (x, y), the
1758 top-level widget containing it is returned. If child is TRUE the child
1759 widget at position (x, y) is returned.
1760
1761 This function is normally rather slow.
1762
1763 See also QCursor::pos(), QWidget::grabMouse(), and
1764 QWidget::grabKeyboard().
1765
1767 [static]
1768 This is an overloaded member function, provided for convenience. It
1769 behaves essentially like the above function.
1770
1771 Returns a pointer to the widget at global screen position pos, or 0 if
1772 there is no Qt widget there.
1773
1774 If child is FALSE and there is a child widget at position pos, the top-
1775 level widget containing it is returned. If child is TRUE the child
1776 widget at position pos is returned.
1777
1779 This virtual function is only implemented under Windows.
1780
1781 The message procedure calls this function for every message received.
1782 Reimplement this function if you want to process window messages that
1783 are not processed by Qt. If you don't want the event to be processed by
1784 Qt, then return TRUE; otherwise return FALSE.
1785
1787 This function is available only on Windows.
1788
1789 If gotFocus is TRUE, widget will become the active window. Otherwise
1790 the active window is reset to NULL.
1791
1793 This function is obsolete. It is provided to keep old source working.
1794 We strongly advise against using it in new code.
1795
1796 Returns the color used to mark selections in windows style.
1797
1798 See also setWinStyleHighlightColor().
1799
1801 This virtual function is only implemented under X11.
1802
1803 If you create an application that inherits QApplication and reimplement
1804 this function, you get direct access to all X events that the are
1805 received from the X server.
1806
1807 Return TRUE if you want to stop the event from being processed. Return
1808 FALSE for normal event dispatching.
1809
1810 See also x11ProcessEvent().
1811
1813 This function does the core processing of individual X events, normally
1814 by dispatching Qt events to the right destination.
1815
1816 It returns 1 if the event was consumed by special handling, 0 if the
1817 event was consumed by normal handling, and -1 if the event was for an
1818 unrecognized widget.
1819
1820 See also x11EventFilter().
1821
1824 Prints a warning message containing the source code file name and line
1825 number if test is FALSE.
1826
1827 This is really a macro defined in qglobal.h.
1828
1829 Q_ASSERT is useful for testing pre- and post-conditions.
1830
1831 Example:
1832
1833 //
1834 // File: div.cpp
1835 //
1836 #include <qglobal.h>
1837 int divide( int a, int b )
1838 {
1839 Q_ASSERT( b != 0 ); // this is line 9
1840 return a/b;
1841 }
1842
1843 If b is zero, the Q_ASSERT statement will output the following message
1844 using the qWarning() function:
1845
1846 ASSERT: "b != 0" in div.cpp (9)
1847
1848 See also qWarning() and Debugging.
1849
1851 If p is 0, prints a warning message containing the source code file
1852 name and line number, saying that the program ran out of memory.
1853
1854 This is really a macro defined in qglobal.h.
1855
1856 Example:
1857
1858 int *a;
1859 Q_CHECK_PTR( a = new int[80] ); // WRONG!
1860 a = new (nothrow) int[80]; // Right
1861 Q_CHECK_PTR( a );
1862
1863 See also qWarning() and Debugging.
1864
1866 Adds a global routine that will be called from the QApplication
1867 destructor. This function is normally used to add cleanup routines for
1868 program-wide functionality.
1869
1870 The function given by p should take no arguments and return nothing,
1871 like this:
1872
1873 static int *global_ptr = 0;
1874 static void cleanup_ptr()
1875 {
1876 delete [] global_ptr;
1877 global_ptr = 0;
1878 }
1879 void init_ptr()
1880 {
1881 global_ptr = new int[100]; // allocate data
1882 qAddPostRoutine( cleanup_ptr ); // delete later
1883 }
1884
1885 Note that for an application- or module-wide cleanup, qAddPostRoutine()
1886 is often not suitable. People have a tendency to make such modules
1887 dynamically loaded, and then unload those modules long before the
1888 QApplication destructor is called, for example.
1889
1890 For modules and libraries, using a reference-counted initialization
1891 manager or Qt' parent-child delete mechanism may be better. Here is an
1892 example of a private class which uses the parent-child mechanism to
1893 call a cleanup function at the right time:
1894
1895 class MyPrivateInitStuff: public QObject {
1896 private:
1897 MyPrivateInitStuff( QObject * parent ): QObject( parent) {
1898 // initialization goes here
1899 }
1900 MyPrivateInitStuff * p;
1901 public:
1902 static MyPrivateInitStuff * initStuff( QObject * parent ) {
1903 if ( !p )
1904 p = new MyPrivateInitStuff( parent );
1905 return p;
1906 }
1907 ~MyPrivateInitStuff() {
1908 // cleanup (the "post routine") goes here
1909 }
1910 }
1911
1912 By selecting the right parent widget/object, this can often be made to
1913 clean up the module's data at the exact right moment.
1914
1916 Prints a debug message msg, or calls the message handler (if it has
1917 been installed).
1918
1919 This function takes a format string and a list of arguments, similar to
1920 the C printf() function.
1921
1922 Example:
1923
1924 qDebug( "my window handle = %x", myWidget->id() );
1925
1926 Under X11, the text is printed to stderr. Under Windows, the text is
1927 sent to the debugger.
1928
1929 Warning: The internal buffer is limited to 8196 bytes (including the
1930 '\0'-terminator).
1931
1932 Warning: Passing (const char *)0 as argument to qDebug might lead to
1933 crashes on certain platforms due to the platforms printf
1934 implementation.
1935
1936 See also qWarning(), qFatal(), qInstallMsgHandler(), and Debugging.
1937
1939 Prints a fatal error message msg and exits, or calls the message
1940 handler (if it has been installed).
1941
1942 This function takes a format string and a list of arguments, similar to
1943 the C printf() function.
1944
1945 Example:
1946
1947 int divide( int a, int b )
1948 {
1949 if ( b == 0 ) // program error
1950 qFatal( "divide: cannot divide by zero" );
1951 return a/b;
1952 }
1953
1954 Under X11, the text is printed to stderr. Under Windows, the text is
1955 sent to the debugger.
1956
1957 Warning: The internal buffer is limited to 8196 bytes (including the
1958 '\0'-terminator).
1959
1960 Warning: Passing (const char *)0 as argument to qFatal might lead to
1961 crashes on certain platforms due to the platforms printf
1962 implementation.
1963
1964 See also qDebug(), qWarning(), qInstallMsgHandler(), and Debugging.
1965
1967 Installs a Qt message handler h. Returns a pointer to the message
1968 handler previously defined.
1969
1970 The message handler is a function that prints out debug messages,
1971 warnings and fatal error messages. The Qt library (debug version)
1972 contains hundreds of warning messages that are printed when internal
1973 errors (usually invalid function arguments) occur. If you implement
1974 your own message handler, you get total control of these messages.
1975
1976 The default message handler prints the message to the standard output
1977 under X11 or to the debugger under Windows. If it is a fatal message,
1978 the application aborts immediately.
1979
1980 Only one message handler can be defined, since this is usually done on
1981 an application-wide basis to control debug output.
1982
1983 To restore the message handler, call qInstallMsgHandler(0).
1984
1985 Example:
1986
1987 #include <qapplication.h>
1988 #include <stdio.h>
1989 #include <stdlib.h>
1990 void myMessageOutput( QtMsgType type, const char *msg )
1991 {
1992 switch ( type ) {
1993 case QtDebugMsg:
1994 fprintf( stderr, "Debug: %s\n", msg );
1995 break;
1996 case QtWarningMsg:
1997 fprintf( stderr, "Warning: %s\n", msg );
1998 break;
1999 case QtFatalMsg:
2000 fprintf( stderr, "Fatal: %s\n", msg );
2001 abort(); // deliberately core dump
2002 }
2003 }
2004 int main( int argc, char **argv )
2005 {
2006 qInstallMsgHandler( myMessageOutput );
2007 QApplication a( argc, argv );
2008 ...
2009 return a.exec();
2010 }
2011
2012 See also qDebug(), qWarning(), qFatal(), and Debugging.
2013
2015 Obtains information about the system.
2016
2017 The system's word size in bits (typically 32) is returned in *wordSize.
2018 The *bigEndian is set to TRUE if this is a big-endian machine, or to
2019 FALSE if this is a little-endian machine.
2020
2021 In debug mode, this function calls qFatal() with a message if the
2022 computer is truly weird (i.e. different endianness for 16 bit and 32
2023 bit integers); in release mode it returns FALSE.
2024
2026 Prints the message msg and uses code to get a system specific error
2027 message. When code is -1 (the default), the system's last error code
2028 will be used if possible. Use this method to handle failures in
2029 platform specific API calls.
2030
2031 This function does nothing when Qt is built with QT_NO_DEBUG defined.
2032
2034 Returns the Qt version number as a string, for example, "2.3.0" or"
2035 3.0.5".
2036
2037 The QT_VERSION define has the numeric value in the form: 0xmmiibb (m =
2038 major, i = minor, b = bugfix). For example, Qt 3.0.5's QT_VERSION is
2039 0x030005.
2040
2042 Prints a warning message msg, or calls the message handler (if it has
2043 been installed).
2044
2045 This function takes a format string and a list of arguments, similar to
2046 the C printf() function.
2047
2048 Example:
2049
2050 void f( int c )
2051 {
2052 if ( c > 200 )
2053 qWarning( "f: bad argument, c == %d", c );
2054 }
2055
2056 Under X11, the text is printed to stderr. Under Windows, the text is
2057 sent to the debugger.
2058
2059 Warning: The internal buffer is limited to 8196 bytes (including the
2060 '\0'-terminator).
2061
2062 Warning: Passing (const char *)0 as argument to qWarning might lead to
2063 crashes on certain platforms due to the platforms printf
2064 implementation.
2065
2066 See also qDebug(), qFatal(), qInstallMsgHandler(), and Debugging.
2067
2068
2070 http://doc.trolltech.com/qapplication.html
2071 http://www.trolltech.com/faq/tech.html
2072
2074 Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
2075 license file included in the distribution for a complete license
2076 statement.
2077
2079 Generated automatically from the source code.
2080
2082 If you find a bug in Qt, please report it as described in
2083 http://doc.trolltech.com/bughowto.html. Good bug reports help us to
2084 help you. Thank you.
2085
2086 The definitive Qt documentation is provided in HTML format; it is
2087 located at $QTDIR/doc/html and can be read using Qt Assistant or with a
2088 web browser. This man page is provided as a convenience for those users
2089 who prefer man pages, although this format is not officially supported
2090 by Trolltech.
2091
2092 If you find errors in this manual page, please report them to qt-
2093 bugs@trolltech.com. Please include the name of the manual page
2094 (qapplication.3qt) and the Qt version (3.3.8).
2095
2096
2097
2098Trolltech AS 2 February 2007 QApplication(3qt)