This repository has been archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dtk-core-dobject-proxy.html
119 lines (110 loc) · 5.64 KB
/
dtk-core-dobject-proxy.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dtk::Core::DObject Proxy Page | Dtk Reference Documentation 1.0.0</title>
<link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
<script type="text/javascript">
document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
// loading style sheet breaks anchors that were jumped to before
// so force jumping to anchor again
setTimeout(function() {
var anchor = location.hash;
// need to jump to different anchor first (e.g. none)
location.hash = "#";
setTimeout(function() {
location.hash = anchor;
}, 0);
}, 0);
</script>
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li><a href="index.html">Dtk Doc</a></li>
<li><a href="index.html">Dtk Reference Documentation</a></li>
<li>Dtk::Core::DObject Proxy Page</li>
<li id="buildversion"><a href="index.html">Qt 5.15.2 Reference Documentation</a></li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<h1 class="title">Dtk::Core::DObject Proxy Page</h1>
<a name="macros"></a>
<h2 id="macros">Macros</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="dtk-core-dobject-proxy.html#D_PRIVATE_SLOT">D_PRIVATE_SLOT</a></b>(<i>Func</i>)</td></tr>
</table></div>
<a name="details"></a>
<div class="macros">
<h2>Macro Documentation</h2>
<!-- $$$D_PRIVATE_SLOT[overload1]$$$D_PRIVATE_SLOT -->
<h3 class="fn" id="D_PRIVATE_SLOT"><a name="D_PRIVATE_SLOT"></a><span class="name">D_PRIVATE_SLOT</span>(<i>Func</i>)</h3>
<p>同 Q_PRIVATE_SLOT,用在继承了 <a href="http://doc.qt.io/qt-5/qobject.html">QObject</a> 的公开类中,在公开类中定一个槽函数,且函数 必须在私有类中有实现。用这个方式定义的槽函数无法被直接调用,只能用于 <a href="http://doc.qt.io/qt-5/qobject.html#connect">QObject::connect</a> 使用 SIGNAL 和 SLOT 的方式连接信号,或者使用 <a href="http://doc.qt.io/qt-5/qmetaobject.html#invokeMethod">QMetaObject::invokeMethod</a> 调用。 一般来讲,这个槽函数应该只在类内部使用,外界不应该通过任何方式来调用它。</p>
<p>例子:</p>
<p>a.h</p>
<pre class="cpp">
<span class="keyword">class</span> APrivate;
<span class="keyword">class</span> A : <span class="keyword">public</span> DObject
{
D_DECLARE_PRIVATE(A)
<span class="keyword">public</span>:
A();
<span class="keyword">protected</span>:
A(APrivate <span class="operator">&</span>dd<span class="operator">,</span> DObject <span class="operator">*</span>parent <span class="operator">=</span> nullptr);
<span class="keyword">private</span>:
D_PRIVATE_SLOT(<span class="type">void</span> _q_testSlot() <span class="keyword">const</span>)
};
</pre>
<p>a.cpp</p>
<pre class="cpp">
<span class="keyword">class</span> APrivate : <span class="keyword">public</span> DObjectPrivate
{
<span class="keyword">public</span>:
D_DECLARE_PUBLIC(A)
APrivate(A <span class="operator">*</span>qq)
: DObjectPrivate(qq)
{
<span class="type"><a href="http://doc.qt.io/qt-5/qtimer.html">QTimer</a></span> <span class="operator">*</span>timer <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="http://doc.qt.io/qt-5/qtimer.html">QTimer</a></span>();
<span class="type"><a href="http://doc.qt.io/qt-5/qobject.html">QObject</a></span><span class="operator">::</span>connect(timer<span class="operator">,</span> SIGNAL(timeout())<span class="operator">,</span> qq<span class="operator">,</span> SLOT(_q_testSlot()));
timer<span class="operator">-</span><span class="operator">></span>start(<span class="number">1000</span>);
}
<span class="type">void</span> _q_testSlot() <span class="keyword">const</span>
{
<a href="http://doc.qt.io/qt-5/qtglobal.html#qDebug">qDebug</a>() <span class="operator"><</span><span class="operator"><</span> <span class="string">"slot"</span>;
}
};
A<span class="operator">::</span>A()
: DObject(<span class="operator">*</span><span class="keyword">new</span> APrivate(<span class="keyword">this</span>))
{
}
A<span class="operator">::</span>A(APrivate <span class="operator">&</span>dd<span class="operator">,</span> DObject <span class="operator">*</span>parent)
: DObject(dd<span class="operator">,</span> parent)
{
}
<span class="preprocessor">#include "moc_a.cpp"</span>
</pre>
<p><i>Func</i> 槽函数的完整签名</p>
<p><b>Note: </b>添加或更新私有槽之后需要重新手动调用 qmake</p>
<p><b>See also </b><a href="dtk-core-dobject-proxy.html#D_DECLARE_PUBLIC">D_DECLARE_PUBLIC</a> and <a href="dtk-core-dobject-proxy.html#D_Q">D_Q</a>.</p>
<!-- @@@D_PRIVATE_SLOT -->
</div>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2020 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br/> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br/> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>