source: trunk/doc/html/qcustomevent.html@ 208

Last change on this file since 208 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 5.8 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qevent.cpp:2197 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QCustomEvent Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QCustomEvent Class Reference</h1>
33
34<p>The QCustomEvent class provides support for custom events.
35<a href="#details">More...</a>
36<p><tt>#include &lt;<a href="qevent-h.html">qevent.h</a>&gt;</tt>
37<p>Inherits <a href="qevent.html">QEvent</a>.
38<p><a href="qcustomevent-members.html">List of all member functions.</a>
39<h2>Public Members</h2>
40<ul>
41<li class=fn><a href="#QCustomEvent"><b>QCustomEvent</b></a> ( int&nbsp;type )</li>
42<li class=fn><a href="#QCustomEvent-2"><b>QCustomEvent</b></a> ( Type&nbsp;type, void&nbsp;*&nbsp;data )</li>
43<li class=fn>void * <a href="#data"><b>data</b></a> () const</li>
44<li class=fn>void <a href="#setData"><b>setData</b></a> ( void&nbsp;*&nbsp;data )</li>
45</ul>
46<hr><a name="details"></a><h2>Detailed Description</h2>
47
48
49The QCustomEvent class provides support for custom events.
50<p>
51<p> QCustomEvent is a generic event class for user-defined events.
52User defined events can be sent to widgets or other <a href="qobject.html">QObject</a>
53instances using <a href="qapplication.html#postEvent">QApplication::postEvent</a>() or
54<a href="qapplication.html#sendEvent">QApplication::sendEvent</a>(). Subclasses of QObject can easily
55receive custom events by implementing the <a href="qobject.html#customEvent">QObject::customEvent</a>()
56event handler function.
57<p> QCustomEvent objects should be created with a type ID that
58uniquely identifies the event type. To avoid clashes with the
59Qt-defined events types, the value should be at least as large as
60the value of the "User" entry in the QEvent::Type enum.
61<p> QCustomEvent contains a generic void* data member that may be used
62for transferring event-specific data to the receiver. Note that
63since events are normally delivered asynchronously, the data
64pointer, if used, must remain valid until the event has been
65received and processed.
66<p> QCustomEvent can be used as-is for simple user-defined event
67types, but normally you will want to make a subclass of it for
68your event types. In a subclass, you can add data members that are
69suitable for your event type.
70<p> Example:
71<pre>
72 class ColorChangeEvent : public QCustomEvent
73 {
74 public:
75 ColorChangeEvent( <a href="qcolor.html">QColor</a> color )
76 : QCustomEvent( 65432 ), c( color ) {}
77 <a href="qcolor.html">QColor</a> color() const { return c; }
78 private:
79 <a href="qcolor.html">QColor</a> c;
80 };
81
82 // To send an event of this custom event type:
83
84 ColorChangeEvent* ce = new ColorChangeEvent( blue );
85 QApplication::<a href="qapplication.html#postEvent">postEvent</a>( receiver, ce ); // Qt will delete it when done
86
87 // To receive an event of this custom event type:
88
89 void MyWidget::customEvent( QCustomEvent * e )
90 {
91 if ( e-&gt;<a href="qevent.html#type">type</a>() == 65432 ) { // It must be a ColorChangeEvent
92 ColorChangeEvent* ce = (ColorChangeEvent*)e;
93 newColor = ce-&gt;color();
94 }
95 }
96 </pre>
97
98<p> <p>See also <a href="qobject.html#customEvent">QWidget::customEvent</a>(), <a href="qapplication.html#notify">QApplication::notify</a>(), and <a href="events.html">Event Classes</a>.
99
100<hr><h2>Member Function Documentation</h2>
101<h3 class=fn><a name="QCustomEvent"></a>QCustomEvent::QCustomEvent ( int&nbsp;type )
102</h3>
103Constructs a custom event object with event type <em>type</em>. The
104value of <em>type</em> must be at least as large as QEvent::User. The
105data pointer is set to 0.
106
107<h3 class=fn><a name="QCustomEvent-2"></a>QCustomEvent::QCustomEvent ( <a href="qevent.html#Type-enum">Type</a>&nbsp;type, void&nbsp;*&nbsp;data )
108</h3>
109
110<p> Constructs a custom event object with the event type <em>type</em> and a
111pointer to <em>data</em>. (Note that any int value may safely be cast to
112QEvent::Type).
113
114<h3 class=fn>void * <a name="data"></a>QCustomEvent::data () const
115</h3>
116
117<p> Returns a pointer to the generic event data.
118<p> <p>See also <a href="#setData">setData</a>().
119
120<h3 class=fn>void <a name="setData"></a>QCustomEvent::setData ( void&nbsp;*&nbsp;data )
121</h3>
122
123<p> Sets the generic data pointer to <em>data</em>.
124<p> <p>See also <a href="#data">data</a>().
125
126<!-- eof -->
127<hr><p>
128This file is part of the <a href="index.html">Qt toolkit</a>.
129Copyright &copy; 1995-2007
130<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
131<table width=100% cellspacing=0 border=0><tr>
132<td>Copyright &copy; 2007
133<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
134<td align=right><div align=right>Qt 3.3.8</div>
135</table></div></address></body>
136</html>
Note: See TracBrowser for help on using the repository browser.