~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qsignalspy.html

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-10-12 23:14:14 UTC
  • mto: (15.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20061012231414-y2oqbom5dy389os0
Tags: upstream-4.2.0
ImportĀ upstreamĀ versionĀ 4.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<!DOCTYPE html
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
 
<!-- /tmp/qt-4.1.4-harald-1150713676011/qt-x11-opensource-src-4.1.4/doc/src/qsignalspy.qdoc -->
6
 
<!-- /tmp/qt-4.1.4-harald-1150713676011/qt-x11-opensource-src-4.1.4/doc/src/qsignalspy.qdoc -->
 
5
<!-- /tmp/qt-4.2.0-qt-1159540607313/qt-x11-opensource-src-4.2.0/doc/src/qsignalspy.qdoc -->
7
6
<head>
8
 
    <title>Qt 4.1: QSignalSpy Class Reference</title>
9
 
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
10
 
a:link { color: #004faf; text-decoration: none }
11
 
a:visited { color: #672967; text-decoration: none }
12
 
td.postheader { font-family: sans-serif }
13
 
tr.address { font-family: sans-serif }
14
 
body { background: #ffffff; color: black; }</style>
 
7
  <title>Qt 4.2: QSignalSpy Class Reference</title>
 
8
  <link href="classic.css" rel="stylesheet" type="text/css" />
15
9
</head>
16
10
<body>
17
11
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
12
<tr>
19
 
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
13
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
20
14
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
21
 
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QSignalSpy Class Reference<br /><sup><sup>[<a href="qttest.html">QtTest</a> module]</sup></sup></h1>
 
15
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QSignalSpy Class Reference<br /><sup><sup>[<a href="qttest.html">QtTest</a> module]</sup></sup></h1>
22
16
<p>The QSignalSpy class enables introspection of signal emission. <a href="#details">More...</a></p>
23
 
<pre>#include &lt;QSignalSpy&gt;</pre><p>Inherits <a href="qobject.html">QObject</a> and <a href="qlist.html">QList&lt;QList&lt;QVariant&gt; &gt;</a>.</p>
 
17
<pre> #include &lt;QSignalSpy&gt;</pre><p>Inherits <a href="qobject.html">QObject</a> and <a href="qlist.html">QList&lt;QList&lt;QVariant&gt; &gt;</a>.</p>
24
18
<ul>
25
19
<li><a href="qsignalspy-members.html">List of all members, including inherited members</a></li>
26
20
</ul>
32
26
<li><div class="fn"/>QByteArray <b><a href="qsignalspy.html#signal">signal</a></b> () const</li>
33
27
</ul>
34
28
<ul>
35
 
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
29
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
36
30
<li><div class="fn"/>60 public functions inherited from <a href="qlist.html#public-functions">QList</a></li>
37
31
</ul>
38
32
<h3>Additional Inherited Members</h3>
40
34
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
41
35
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
42
36
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
43
 
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
37
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
44
38
<li><div class="fn"/>3 static public members inherited from <a href="qlist.html#static-public-members">QList</a></li>
45
39
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
46
40
</ul>
50
44
<p>The QSignalSpy class enables introspection of signal emission.</p>
51
45
<p>QSignalSpy can connect to any signal of any object and records its emission. QSignalSpy itself is a list of <a href="qvariant.html">QVariant</a> lists. Each emission of the signal will append one item to the list, containing the arguments of the signal.</p>
52
46
<p>The following example records all signal emissions for the <tt>clicked()</tt> signal of a <a href="qcheckbox.html">QCheckBox</a>:</p>
53
 
<pre>&nbsp;   QCheckBox *box = ...;
54
 
    QSignalSpy spy(box, SIGNAL(clicked(bool)));
55
 
 
56
 
    // do something that triggers the signal
57
 
    box-&gt;animateClick();
58
 
 
59
 
    COMPARE(spy.count(), 1); // make sure the signal was emitted exactly one time
60
 
    QList&lt;QVariant&gt; arguments = spy.takeFirst(); // take the first signal
61
 
 
62
 
    VERIFY(arguments.at(0).toBool() == true); // verify the first argument</pre>
 
47
<pre> QCheckBox *box = ...;
 
48
 QSignalSpy spy(box, SIGNAL(clicked(bool)));
 
49
 
 
50
<span class="comment"> // do something that triggers the signal</span>
 
51
 box-&gt;animateClick();
 
52
 
 
53
 COMPARE(spy.count(), 1); <span class="comment">// make sure the signal was emitted exactly one time</span>
 
54
 QList&lt;QVariant&gt; arguments = spy.takeFirst(); <span class="comment">// take the first signal</span>
 
55
 
 
56
 VERIFY(arguments.at(0).toBool() == true); <span class="comment">// verify the first argument</span></pre>
63
57
<p><tt>spy.takeFirst()</tt> returns the arguments for the first emitted signal, as a list of <a href="qvariant.html">QVariant</a> objects. The <tt>clicked()</tt> signal has a single bool argument, which is stored as the first entry in the list of arguments.</p>
64
58
<p>The example below catches a signal from a custom object:</p>
65
 
<pre>&nbsp;   QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)));
66
 
 
67
 
    myCustomObject-&gt;doSomething(); // trigger emission of the signal
68
 
 
69
 
    QList&lt;QVariant&gt; arguments = spy.takeFirst();
70
 
    VERIFY(arguments.at(0).type() == QVariant::Int);
71
 
    VERIFY(arguments.at(1).type() == QVariant::QString);
72
 
    VERIFY(arguments.at(2).type() == QVariant::double);</pre>
 
59
<pre> QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)));
 
60
 
 
61
 myCustomObject-&gt;doSomething(); <span class="comment">// trigger emission of the signal</span>
 
62
 
 
63
 QList&lt;QVariant&gt; arguments = spy.takeFirst();
 
64
 VERIFY(arguments.at(0).type() == QVariant::Int);
 
65
 VERIFY(arguments.at(1).type() == QVariant::QString);
 
66
 VERIFY(arguments.at(2).type() == QVariant::double);</pre>
73
67
<p><b>Note:</b> Non-standard data types need to be registered, using the <a href="qmetatype.html#qRegisterMetaType">qRegisterMetaType</a>() function, before you can create a QSignalSpy. For example:</p>
74
 
<pre>&nbsp;   qRegisterMetaType&lt;QModelIndex&gt;(&quot;QModelIndex&quot;);
75
 
    QSignalSpy spy(&amp;model, SIGNAL(whatever(QModelIndex)));</pre>
 
68
<pre> qRegisterMetaType&lt;QModelIndex&gt;(&quot;QModelIndex&quot;);
 
69
 QSignalSpy spy(&amp;model, SIGNAL(whatever(QModelIndex)));</pre>
76
70
<p>To retrieve the <tt>QModelIndex</tt>, you can use qvariant_cast:</p>
77
 
<pre>&nbsp;   // get the first argument from the first received signal:
78
 
    QModelIndex result = qvariant_cast&lt;QModelIndex&gt;(spy.at(0).at(0));</pre>
 
71
<pre><span class="comment"> // get the first argument from the first received signal:</span>
 
72
 QModelIndex result = qvariant_cast&lt;QModelIndex&gt;(spy.at(0).at(0));</pre>
79
73
<hr />
80
74
<h2>Member Function Documentation</h2>
81
75
<h3 class="fn"><a name="QSignalSpy"></a>QSignalSpy::QSignalSpy ( <a href="qobject.html">QObject</a> * <i>object</i>, const char * <i>signal</i> )</h3>
82
76
<p>Constructs a new <a href="qsignalspy.html">QSignalSpy</a> that listens for emissions of the <i>signal</i> from the <a href="qobject.html">QObject</a> <i>object</i>. Neither <i>signal</i> nor <i>object</i> can be null.</p>
83
77
<p>Example:</p>
84
 
<pre>&nbsp;   QSignalSpy spy(myPushButton, SIGNAL(clicked(bool)));</pre>
 
78
<pre> QSignalSpy spy(myPushButton, SIGNAL(clicked(bool)));</pre>
85
79
<h3 class="fn"><a name="isValid"></a>bool QSignalSpy::isValid () const</h3>
86
80
<p>Returns true if the signal spy listens to a valid signal, otherwise false.</p>
87
81
<h3 class="fn"><a name="signal"></a><a href="qbytearray.html">QByteArray</a> QSignalSpy::signal () const</h3>
90
84
<table width="100%" cellspacing="0" border="0"><tr class="address">
91
85
<td width="30%">Copyright &copy; 2006 <a href="trolltech.html">Trolltech</a></td>
92
86
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
93
 
<td width="30%" align="right"><div align="right">Qt 4.1.4</div></td>
 
87
<td width="30%" align="right"><div align="right">Qt 4.2.0</div></td>
94
88
</tr></table></div></address></body>
95
89
</html>