[190] | 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"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { 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 Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main 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 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 |
|
---|
| 36 | The ActiveX control in this example uses the QGlWidget class in
|
---|
| 37 | Qt to render an OpenGL scene in an ActiveX. The control exposes a few
|
---|
| 38 | methods to change the scene. The example is based on the
|
---|
| 39 | <a href="opengl-box-example.html">"box" example</a> from the standard
|
---|
| 40 | Qt 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
|
---|
| 43 | interface using <a href="qaxbindable.html">QAxBindable</a> and <a href="qaxaggregated.html">QAxAggregated</a>. The server executable
|
---|
| 44 | can run both as an ActiveX server and as a stand alone application.
|
---|
| 45 | <p>
|
---|
| 46 |
|
---|
| 47 | The 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
|
---|
| 49 | control.
|
---|
| 50 | <pre> #include <<a href="qaxfactory-h.html">qaxfactory.h</a>>
|
---|
| 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,
|
---|
| 60 | and uses <a href="qaxfactory.html#isServer">QAxFactory::isServer</a>() to determine whether or not it is
|
---|
| 61 | appropriate 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>( &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 |
|
---|
| 88 | The <tt>GLBox</tt> class inherits from both the <a href="qglwidget.html">QGLWidget</a> class to be able
|
---|
| 89 | to render OpenGL, and from <a href="qaxbindable.html">QAxBindable</a>.
|
---|
| 90 | <pre> #include <<a href="qaxbindable-h.html">qaxbindable.h</a>>
|
---|
| 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>
|
---|
| 97 | to 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
|
---|
| 109 | rendering is identical to the original "box" example.
|
---|
| 110 | <p>
|
---|
| 111 |
|
---|
| 112 | The implementation file of the <tt>GLBox</tt> class includes the <tt>objsafe.h</tt>
|
---|
| 113 | system header, in which the <tt>IObjectSafety</tt> COM interface is defined.
|
---|
| 114 | <pre> #include <objsafe.h>
|
---|
| 115 | </pre>A class <tt>ObjectSafetyImpl</tt> is declared using multiple inheritance
|
---|
| 116 | to subclass the <a href="qaxaggregated.html">QAxAggregated</a> class, and to implement the IObjectSafety
|
---|
| 117 | interface.
|
---|
| 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
|
---|
| 123 | function to support the IObjectSafety interface.
|
---|
| 124 | <pre> ObjectSafetyImpl() {}
|
---|
| 125 |
|
---|
| 126 | long queryInterface( const <a href="quuid.html">QUuid</a> &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
|
---|
| 138 | is used to provide the default implementation of the <tt>IUnknown</tt> interface.
|
---|
| 139 | The macro is defined to delegate all calls to <tt>QueryInterface</tt>, <tt>AddRef</tt>
|
---|
| 140 | and <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
|
---|
| 143 | with 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
|
---|
| 167 | WebBrowser to support ActiveX controls, and scripting to be enabled.
|
---|
| 168 | <p> In contrast to the other QAxServer examples Internet Explorer will not
|
---|
| 169 | open a dialog box to ask the user whether or not the scripting of the GLBox
|
---|
| 170 | control should be allowed (the exact browser behaviour depends on the security
|
---|
| 171 | settings in the Internet Options dialog).
|
---|
| 172 | <p>
|
---|
| 173 |
|
---|
| 174 | <pre> <SCRIPT LANGUAGE=JavaScript>
|
---|
| 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 | </SCRIPT>
|
---|
| 182 |
|
---|
| 183 | <p>
|
---|
| 184 | An OpenGL scene:<br>
|
---|
| 185 | <object ID="GLBox" CLASSID="CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0"
|
---|
| 186 | CODEBASE=http://www.trolltech.com/demos/openglax.cab>
|
---|
| 187 | [Object not available! Did you forget to build and register the server?]
|
---|
| 188 | </object><br>
|
---|
| 189 |
|
---|
| 190 | <form>
|
---|
| 191 | Rotate the scene:<br>
|
---|
| 192 | X:<input type="edit" ID="XEdit" value="0"><br>
|
---|
| 193 | Y:<input type="edit" name="YEdit" value="0"><br>
|
---|
| 194 | Z:<input type="edit" name="ZEdit" value="0"><br>
|
---|
| 195 | <input type="button" value="Set" onClick="setRot(this.form)">
|
---|
| 196 | </form>
|
---|
| 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 © 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>
|
---|