summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqcustomevent.3qt
blob: aa7f5d26a62a72f3eea2f5af4eaacded72f49ad8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'\" t
.TH QCustomEvent 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QCustomEvent \- Support for custom events
.SH SYNOPSIS
\fC#include <ntqevent.h>\fR
.PP
Inherits QEvent.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQCustomEvent\fR ( int type )"
.br
.ti -1c
.BI "\fBQCustomEvent\fR ( Type type, void * data )"
.br
.ti -1c
.BI "void * \fBdata\fR () const"
.br
.ti -1c
.BI "void \fBsetData\fR ( void * data )"
.br
.in -1c
.SH DESCRIPTION
The QCustomEvent class provides support for custom events.
.PP
QCustomEvent is a generic event class for user-defined events. User defined events can be sent to widgets or other TQObject instances using QApplication::postEvent() or QApplication::sendEvent(). Subclasses of TQObject can easily receive custom events by implementing the TQObject::customEvent() event handler function.
.PP
QCustomEvent objects should be created with a type ID that uniquely identifies the event type. To avoid clashes with the Qt-defined events types, the value should be at least as large as the value of the "User" entry in the QEvent::Type enum.
.PP
QCustomEvent contains a generic void* data member that may be used for transferring event-specific data to the receiver. Note that since events are normally delivered asynchronously, the data pointer, if used, must remain valid until the event has been received and processed.
.PP
QCustomEvent can be used as-is for simple user-defined event types, but normally you will want to make a subclass of it for your event types. In a subclass, you can add data members that are suitable for your event type.
.PP
Example:
.PP
.nf
.br
    class ColorChangeEvent : public QCustomEvent
.br
    {
.br
    public:
.br
        ColorChangeEvent( TQColor color )
.br
            : QCustomEvent( 65432 ), c( color ) {}
.br
        TQColor color() const { return c; }
.br
    private:
.br
        TQColor c;
.br
    };
.br
.br
    // To send an event of this custom event type:
.br
.br
    ColorChangeEvent* ce = new ColorChangeEvent( blue );
.br
    QApplication::postEvent( receiver, ce );  // TQt will delete it when done
.br
.br
    // To receive an event of this custom event type:
.br
.br
    void MyWidget::customEvent( QCustomEvent * e )
.br
    {
.br
        if ( e->type() == 65432 ) {  // It must be a ColorChangeEvent
.br
            ColorChangeEvent* ce = (ColorChangeEvent*)e;
.br
            newColor = ce->color();
.br
        }
.br
    }
.br
.fi
.PP
See also TQWidget::customEvent(), QApplication::notify(), and Event Classes.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QCustomEvent::QCustomEvent ( int type )"
Constructs a custom event object with event type \fItype\fR. The value of \fItype\fR must be at least as large as QEvent::User. The data pointer is set to 0.
.SH "QCustomEvent::QCustomEvent ( Type type, void * data )"
Constructs a custom event object with the event type \fItype\fR and a pointer to \fIdata\fR. (Note that any int value may safely be cast to QEvent::Type).
.SH "void * QCustomEvent::data () const"
Returns a pointer to the generic event data.
.PP
See also setData().
.SH "void QCustomEvent::setData ( void * data )"
Sets the generic data pointer to \fIdata\fR.
.PP
See also data().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/qcustomevent.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqcustomevent.3qt) and the Qt
version (3.3.8).