source: trunk/doc/html/qaxserver-example-opengl.html@ 190

Last change on this file since 190 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 9.2 KB
Line 
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/extensions/activeqt/examples/opengl/opengl.doc:33 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>Qt' OpenGL widgets as an ActiveX (executable)</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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>Qt' OpenGL widgets as an ActiveX (executable)</h1>
33
34
35
36The ActiveX control in this example uses the QGlWidget class in
37Qt to render an OpenGL scene in an ActiveX. The control exposes a few
38methods to change the scene. The example is based on the
39<a href="opengl-box-example.html">"box" example</a> from the standard
40Qt distribution.
41<p> The example demonstrates the use of the default factory and
42<a href="qaxfactory.html#isServer">QAxFactory::isServer</a>(), and the implementation of an additional COM
43interface using <a href="qaxbindable.html">QAxBindable</a> and <a href="qaxaggregated.html">QAxAggregated</a>. The server executable
44can run both as an ActiveX server and as a stand alone application.
45<p>
46
47The application uses the default factory as provided by the
48<a href="qaxfactory.html#QAXFACTORY_DEFAULT">QAXFACTORY_DEFAULT</a> macro to expose the <tt>GLBox</tt> widget as an ActiveX
49control.
50<pre> #include &lt;<a href="qaxfactory-h.html">qaxfactory.h</a>&gt;
51
52 QAXFACTORY_DEFAULT( GLBox,
53 "{5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}",
54 "{33b051af-bb25-47cf-a390-5cfd2987d26a}",
55 "{8c996c29-eafa-46ac-a6f9-901951e765b5}",
56 "{2c3c183a-eeda-41a4-896e-3d9c12c3577d}",
57 "{83e16271-6480-45d5-aaf1-3f40b7661ae4}"
58 )
59</pre>The implementation of <tt>main</tt> initializes the <a href="qapplication.html">QApplication</a> object,
60and uses <a href="qaxfactory.html#isServer">QAxFactory::isServer</a>() to determine whether or not it is
61appropriate to create and show the application interface.
62<pre> /*
63 The main program is here.
64 */
65
66 int main( int argc, char **argv )
67 {
68 <a name="x2732"></a> QApplication::<a href="qapplication.html#setColorSpec">setColorSpec</a>( QApplication::CustomColor );
69 <a href="qapplication.html">QApplication</a> a(argc,argv);
70
71 if ( !QGLFormat::hasOpenGL() ) {
72 <a href="qapplication.html#qWarning">qWarning</a>( "This system has no OpenGL support. Exiting." );
73 return -1;
74 }
75
76 if ( !QAxFactory::isServer() ) {
77 GLObjectWindow w;
78 w.<a href="qwidget.html#resize">resize</a>( 400, 350 );
79 <a name="x2733"></a> a.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;w );
80 w.<a href="qwidget.html#show">show</a>();
81 return a.<a href="qapplication.html#exec">exec</a>();
82 }
83 <a name="x2731"></a> return a.<a href="qapplication.html#exec">exec</a>();
84 }
85</pre>
86<p>
87
88The <tt>GLBox</tt> class inherits from both the <a href="qglwidget.html">QGLWidget</a> class to be able
89to render OpenGL, and from <a href="qaxbindable.html">QAxBindable</a>.
90<pre> #include &lt;<a href="qaxbindable-h.html">qaxbindable.h</a>&gt;
91
92 class GLBox : public <a href="qglwidget.html">QGLWidget</a>,
93 public QAxBindable
94 {
95 <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>
96</pre>The class reimplements the <a href="qaxbindable.html#createAggregate">QAxBindable::createAggregate</a>() function from <a href="qaxbindable.html">QAxBindable</a>
97to return the pointer to a <a href="qaxaggregated.html">QAxAggregated</a> object.
98<pre> public:
99
100 GLBox( <a href="qwidget.html">QWidget</a>* parent, const char* name );
101 ~GLBox();
102
103 <a href="qaxaggregated.html">QAxAggregated</a> *createAggregate();
104
105 public slots:
106
107 void setXRotation( int degrees );
108</pre>The rest of the class declaration and the implementation of the OpenGL
109rendering is identical to the original "box" example.
110<p>
111
112The implementation file of the <tt>GLBox</tt> class includes the <tt>objsafe.h</tt>
113system header, in which the <tt>IObjectSafety</tt> COM interface is defined.
114<pre> #include &lt;objsafe.h&gt;
115</pre>A class <tt>ObjectSafetyImpl</tt> is declared using multiple inheritance
116to subclass the <a href="qaxaggregated.html">QAxAggregated</a> class, and to implement the IObjectSafety
117interface.
118<pre> class ObjectSafetyImpl : public <a href="qaxaggregated.html">QAxAggregated</a>,
119 public IObjectSafety
120 {
121 public:
122</pre>The class declares a default constructor, and implements the queryInterface
123function to support the IObjectSafety interface.
124<pre> ObjectSafetyImpl() {}
125
126 long queryInterface( const <a href="quuid.html">QUuid</a> &amp;iid, void **iface )
127 {
128 *iface = 0;
129 if ( iid == IID_IObjectSafety )
130 *iface = (IObjectSafety*)this;
131 else
132 return E_NOINTERFACE;
133
134 AddRef();
135 return S_OK;
136 }
137</pre>Since every COM interface inherits <tt>IUnknown</tt> the <tt>QAXAGG_IUNKNOWN</tt> macro
138is used to provide the default implementation of the <tt>IUnknown</tt> interface.
139The macro is defined to delegate all calls to <tt>QueryInterface</tt>, <tt>AddRef</tt>
140and <tt>Release</tt> to the interface returned by the controllingUnknown() function.
141<pre> QAXAGG_IUNKNOWN;
142</pre>The implementation of the <tt>IObjectSafety</tt> interface provides the caller
143with information about supported and enabled safety options, and returns
144<tt>S_OK</tt> for all calls to indicate that the ActiveX control is safe.
145<pre> HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions )
146 {
147 *pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
148 *pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_DATA | INTERFACESAFE_FOR_UNTRUSTED_CALLER;
149 return S_OK;
150 }
151 HRESULT WINAPI SetInterfaceSafetyOptions( REFIID riid, DWORD pdwSupportedOptions, DWORD pdwEnabledOptions )
152 {
153 return S_OK;
154 }
155 };
156</pre>The implementation of the <tt>createAggregate()</tt> function just returns a new
157<tt>ObjectSafetyImpl</tt> object.
158<pre> QAxAggregated *GLBox::createAggregate()
159 {
160 return new ObjectSafetyImpl();
161 }
162</pre>
163<p> To build the example you must first build the <a href="qaxserver.html">QAxServer</a> library. Then run qmake and your make tool in
164<tt>examples/wrapper</tt>.
165<p> <hr>
166<p> The <a href="qaxserver-demo-opengl.html">demonstration</a> requires your
167WebBrowser to support ActiveX controls, and scripting to be enabled.
168<p> In contrast to the other QAxServer examples Internet Explorer will not
169open a dialog box to ask the user whether or not the scripting of the GLBox
170control should be allowed (the exact browser behaviour depends on the security
171settings in the Internet Options dialog).
172<p>
173
174<pre> &lt;SCRIPT LANGUAGE=JavaScript&gt;
175 function setRot( form )
176 {
177 GLBox.setXRotation( form.XEdit.value );
178 GLBox.setYRotation( form.YEdit.value );
179 GLBox.setZRotation( form.ZEdit.value );
180 }
181 &lt;/SCRIPT&gt;
182
183 &lt;p&gt;
184 An OpenGL scene:&lt;br&gt;
185 &lt;object ID="GLBox" CLASSID="CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0"
186 CODEBASE=http://www.trolltech.com/demos/openglax.cab&gt;
187 [Object not available! Did you forget to build and register the server?]
188 &lt;/object&gt;&lt;br&gt;
189
190 &lt;form&gt;
191 Rotate the scene:&lt;br&gt;
192 X:&lt;input type="edit" ID="XEdit" value="0"&gt;&lt;br&gt;
193 Y:&lt;input type="edit" name="YEdit" value="0"&gt;&lt;br&gt;
194 Z:&lt;input type="edit" name="ZEdit" value="0"&gt;&lt;br&gt;
195 &lt;input type="button" value="Set" onClick="setRot(this.form)"&gt;
196 &lt;/form&gt;
197</pre><p>See also <a href="qaxserver-examples.html">The QAxServer Examples</a>.
198
199<!-- eof -->
200<p><address><hr><div align=center>
201<table width=100% cellspacing=0 border=0><tr>
202<td>Copyright &copy; 2007
203<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
204<td align=right><div align=right>Qt 3.3.8</div>
205</table></div></address></body>
206</html>
Note: See TracBrowser for help on using the repository browser.