File: activeqt-multiple.html

package info (click to toggle)
qt4-x11 4%3A4.8.2%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 701,696 kB
  • sloc: cpp: 2,686,179; ansic: 375,485; python: 25,859; sh: 19,349; xml: 17,091; perl: 14,765; yacc: 5,383; asm: 5,038; makefile: 1,259; lex: 555; ruby: 526; objc: 347; cs: 112; pascal: 112; php: 54; sed: 34
file content (193 lines) | stat: -rw-r--r-- 11,867 bytes parent folder | download
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- multiple.qdoc -->
  <title>Qt 4.8: Multiple Example (ActiveQt)</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li><a href="all-examples.html">Examples</a></li>
<li>Multiple Example (ActiveQt)</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<h1 class="title">Multiple Example (ActiveQt)</h1>
<span class="subtitle"></span>
<!-- $$$activeqt/multiple-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="activeqt-multiple-ax1-h.html">activeqt/multiple/ax1.h</a></li>
<li><a href="activeqt-multiple-ax2-h.html">activeqt/multiple/ax2.h</a></li>
<li><a href="activeqt-multiple-main-cpp.html">activeqt/multiple/main.cpp</a></li>
<li><a href="activeqt-multiple-multiple-pro.html">activeqt/multiple/multiple.pro</a></li>
</ul>
<p>The Multiple example demonstrates the implementation of a <a href="qaxfactory.html">QAxFactory</a> to provide multiple ActiveX controls in a single in process ActiveX server using the <tt>QAXFACTORY_EXPORT()</tt> macro.<p>The ActiveX controls in this example are simple <a href="qwidget.html">QWidget</a> subclasses that reimplement <a href="qwidget.html#paintEvent">QWidget::paintEvent</a>().</p>
<pre class="cpp"> <span class="keyword">class</span> QAxWidget1 : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
 {
     Q_OBJECT
     Q_CLASSINFO(<span class="string">&quot;ClassID&quot;</span><span class="operator">,</span> <span class="string">&quot;{1D9928BD-4453-4bdd-903D-E525ED17FDE5}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;InterfaceID&quot;</span><span class="operator">,</span> <span class="string">&quot;{99F6860E-2C5A-42ec-87F2-43396F4BE389}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;EventsID&quot;</span><span class="operator">,</span> <span class="string">&quot;{0A3E9F27-E4F1-45bb-9E47-63099BCCD0E3}&quot;</span>)

     Q_PROPERTY(<span class="type"><a href="qcolor.html">QColor</a></span> fillColor READ fillColor WRITE setFillColor)
 <span class="keyword">public</span>:
     QAxWidget1(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>)
         : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)<span class="operator">,</span> fill_color(<span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>red)
     {
     }

     <span class="type"><a href="qcolor.html">QColor</a></span> fillColor() <span class="keyword">const</span>
     {
         <span class="keyword">return</span> fill_color;
     }
     <span class="type">void</span> setFillColor(<span class="keyword">const</span> <span class="type"><a href="qcolor.html">QColor</a></span> <span class="operator">&amp;</span>fc)
     {
         fill_color <span class="operator">=</span> fc;
         repaint();
     }

 <span class="keyword">protected</span>:
     <span class="type">void</span> paintEvent(<span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span>e)
     {
         <span class="type"><a href="qpainter.html">QPainter</a></span> paint(<span class="keyword">this</span>);
         <span class="type"><a href="qrect.html">QRect</a></span> r <span class="operator">=</span> rect();
         r<span class="operator">.</span>adjust(<span class="number">10</span><span class="operator">,</span> <span class="number">10</span><span class="operator">,</span> <span class="operator">-</span><span class="number">10</span><span class="operator">,</span> <span class="operator">-</span><span class="number">10</span>);
         paint<span class="operator">.</span>fillRect(r<span class="operator">,</span> fill_color);
     }

 <span class="keyword">private</span>:
     <span class="type"><a href="qcolor.html">QColor</a></span> fill_color;
 };</pre>
<p>The first control draws a filled rectangle. The fill color is exposed as a property. <tt>Q_CLASSINFO()</tt> is used to specify the COM identifiers.</p>
<pre class="cpp"> <span class="keyword">class</span> QAxWidget2 : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span>
 {
     Q_OBJECT
     Q_CLASSINFO(<span class="string">&quot;ClassID&quot;</span><span class="operator">,</span> <span class="string">&quot;{58139D56-6BE9-4b17-937D-1B1EDEDD5B71}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;InterfaceID&quot;</span><span class="operator">,</span> <span class="string">&quot;{B66280AB-08CC-4dcc-924F-58E6D7975B7D}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;EventsID&quot;</span><span class="operator">,</span> <span class="string">&quot;{D72BACBA-03C4-4480-B4BB-DE4FE3AA14A0}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;ToSuperClass&quot;</span><span class="operator">,</span> <span class="string">&quot;QAxWidget2&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;StockEvents&quot;</span><span class="operator">,</span> <span class="string">&quot;yes&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;Insertable&quot;</span><span class="operator">,</span> <span class="string">&quot;yes&quot;</span>)

     Q_PROPERTY( <span class="type">int</span> lineWidth READ lineWidth WRITE setLineWidth )
 <span class="keyword">public</span>:
     QAxWidget2(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>)
         : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)<span class="operator">,</span> line_width( <span class="number">1</span> )
     {
     }

     <span class="type">int</span> lineWidth() <span class="keyword">const</span>
     {
         <span class="keyword">return</span> line_width;
     }
     <span class="type">void</span> setLineWidth( <span class="type">int</span> lw )
     {
         line_width <span class="operator">=</span> lw;
         repaint();
     }

 <span class="keyword">protected</span>:
     <span class="type">void</span> paintEvent( <span class="type"><a href="qpaintevent.html">QPaintEvent</a></span> <span class="operator">*</span>e )
     {
         <span class="type"><a href="qpainter.html">QPainter</a></span> paint( <span class="keyword">this</span> );
         <span class="type"><a href="qpen.html">QPen</a></span> pen <span class="operator">=</span> paint<span class="operator">.</span>pen();
         pen<span class="operator">.</span>setWidth( line_width );
         paint<span class="operator">.</span>setPen( pen );

         <span class="type"><a href="qrect.html">QRect</a></span> r <span class="operator">=</span> rect();
         r<span class="operator">.</span>adjust( <span class="number">10</span><span class="operator">,</span> <span class="number">10</span><span class="operator">,</span> <span class="operator">-</span><span class="number">10</span><span class="operator">,</span> <span class="operator">-</span><span class="number">10</span> );
         paint<span class="operator">.</span>drawEllipse( r );
     }

 <span class="keyword">private</span>:
     <span class="type">int</span> line_width;
 };</pre>
<p>The second control draws a circle. The linewith is exposed as a property. <tt>Q_CLASSINFO()</tt> is used to specify the COM identifiers, and to set the attributes <i>ToSuperClass</i> and <i>StockEvents</i> to expose only the API of the class itself, and to add COM stock events to the ActiveX control.</p>
<pre class="cpp"> <span class="preprocessor">#include &quot;ax1.h&quot;</span>
 <span class="preprocessor">#include &quot;ax2.h&quot;</span>
 <span class="preprocessor">#include &lt;QAxFactory&gt;</span>

 QT_USE_NAMESPACE

 <a href="qaxfactory.html#QAXFACTORY_BEGIN">QAXFACTORY_BEGIN</a>(<span class="string">&quot;{98DE28B6-6CD3-4e08-B9FA-3D1DB43F1D2F}&quot;</span><span class="operator">,</span> <span class="string">&quot;{05828915-AD1C-47ab-AB96-D6AD1E25F0E2}&quot;</span>)
     <a href="qaxfactory.html#QAXCLASS">QAXCLASS</a>(QAxWidget1)
     <a href="qaxfactory.html#QAXCLASS">QAXCLASS</a>(QAxWidget2)
 <a href="qaxfactory.html#QAXFACTORY_END">QAXFACTORY_END</a>()</pre>
<p>The classes are exported from the server using the <a href="qaxfactory.html">QAxFactory</a> macros.</p>
<p>To build the example you must first build the <a href="qaxserver.html">QAxServer</a> library. Then run <tt>qmake</tt> and your make tool in <tt>examples/activeqt/multiple</tt>.</p>
<p>The <a href="qaxserver-demo-multiple.html">demonstration</a> requires your WebBrowser to support ActiveX controls, and scripting to be enabled.</p>
<pre class="cpp"> &lt;script language=&quot;javascript&quot;&gt;
 function setColor( form )
 {
     Ax1.fillColor = form.colorEdit.value;
 }

 function setWidth( form )
 {
     Ax2.lineWidth = form.widthEdit.value;
 }
 &lt;/script&gt;

 &lt;p /&gt;
 This is one QWidget subclass:&lt;br /&gt;
 &lt;object ID=&quot;Ax1&quot; CLASSID=&quot;CLSID:1D9928BD-4453-4bdd-903D-E525ED17FDE5&quot;
 CODEBASE=&quot;http://qt.nokia.com/demos/multipleax.cab&quot;&gt;
 [Object not available! Did you forget to build and register the server?]
 &lt;/object&gt;&lt;br /&gt;
 &lt;form&gt;
 Fill Color: &lt;input type=&quot;edit&quot; ID=&quot;colorEdit&quot; value = &quot;red&quot; /&gt;
 &lt;input type=&quot;button&quot; value = &quot;Set&quot; onClick=&quot;setColor(this.form)&quot; /&gt;
 &lt;input type=&quot;button&quot; value = &quot;Hide&quot; onClick=&quot;Ax1.hide()&quot; /&gt;
 &lt;input type=&quot;button&quot; value = &quot;Show&quot; onClick=&quot;Ax1.show()&quot; /&gt;
 &lt;/form&gt;

 &lt;p /&gt;
 This is another QWidget subclass:&lt;br /&gt;
 &lt;object ID=&quot;Ax2&quot; CLASSID=&quot;CLSID:58139D56-6BE9-4b17-937D-1B1EDEDD5B71&quot;
 CODEBASE=&quot;http://qt.nokia.com/demos/multipleax.cab&quot;&gt;
 [Object not available! Did you forget to build and register the server?]
 &lt;/object&gt;&lt;br /&gt;
 &lt;form&gt;
 Line width: &lt;input type=&quot;edit&quot; ID=&quot;widthEdit&quot; value = &quot;1&quot; /&gt;
 &lt;input type=&quot;button&quot; value = &quot;Set&quot; onClick=&quot;setWidth(this.form)&quot; /&gt;
 &lt;/form&gt;</pre>
</div>
<!-- @@@activeqt/multiple -->
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2012 Nokia Corporation and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      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.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>