[190] | 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"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { 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 Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main 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 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 <<a href="qevent-h.html">qevent.h</a>></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 type )</li>
|
---|
| 42 | <li class=fn><a href="#QCustomEvent-2"><b>QCustomEvent</b></a> ( Type type, void * 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 * data )</li>
|
---|
| 45 | </ul>
|
---|
| 46 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | The QCustomEvent class provides support for custom events.
|
---|
| 50 | <p>
|
---|
| 51 | <p> QCustomEvent is a generic event class for user-defined events.
|
---|
| 52 | User defined events can be sent to widgets or other <a href="qobject.html">QObject</a>
|
---|
| 53 | instances using <a href="qapplication.html#postEvent">QApplication::postEvent</a>() or
|
---|
| 54 | <a href="qapplication.html#sendEvent">QApplication::sendEvent</a>(). Subclasses of QObject can easily
|
---|
| 55 | receive custom events by implementing the <a href="qobject.html#customEvent">QObject::customEvent</a>()
|
---|
| 56 | event handler function.
|
---|
| 57 | <p> QCustomEvent objects should be created with a type ID that
|
---|
| 58 | uniquely identifies the event type. To avoid clashes with the
|
---|
| 59 | Qt-defined events types, the value should be at least as large as
|
---|
| 60 | the value of the "User" entry in the QEvent::Type enum.
|
---|
| 61 | <p> QCustomEvent contains a generic void* data member that may be used
|
---|
| 62 | for transferring event-specific data to the receiver. Note that
|
---|
| 63 | since events are normally delivered asynchronously, the data
|
---|
| 64 | pointer, if used, must remain valid until the event has been
|
---|
| 65 | received and processed.
|
---|
| 66 | <p> QCustomEvent can be used as-is for simple user-defined event
|
---|
| 67 | types, but normally you will want to make a subclass of it for
|
---|
| 68 | your event types. In a subclass, you can add data members that are
|
---|
| 69 | suitable 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-><a href="qevent.html#type">type</a>() == 65432 ) { // It must be a ColorChangeEvent
|
---|
| 92 | ColorChangeEvent* ce = (ColorChangeEvent*)e;
|
---|
| 93 | newColor = ce->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 type )
|
---|
| 102 | </h3>
|
---|
| 103 | Constructs a custom event object with event type <em>type</em>. The
|
---|
| 104 | value of <em>type</em> must be at least as large as QEvent::User. The
|
---|
| 105 | data 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> type, void * data )
|
---|
| 108 | </h3>
|
---|
| 109 |
|
---|
| 110 | <p> Constructs a custom event object with the event type <em>type</em> and a
|
---|
| 111 | pointer to <em>data</em>. (Note that any int value may safely be cast to
|
---|
| 112 | QEvent::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 * 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>
|
---|
| 128 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
| 129 | Copyright © 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 © 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>
|
---|