File: activeqt-opengl.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 (185 lines) | stat: -rw-r--r-- 13,284 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
<?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" />
<!-- opengl.qdoc -->
  <title>Qt 4.8: OpenGL 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>OpenGL Example (ActiveQt)</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<h1 class="title">OpenGL Example (ActiveQt)</h1>
<span class="subtitle"></span>
<!-- $$$activeqt/opengl-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="activeqt-opengl-glbox-cpp.html">activeqt/opengl/glbox.cpp</a></li>
<li><a href="activeqt-opengl-glbox-h.html">activeqt/opengl/glbox.h</a></li>
<li><a href="activeqt-opengl-globjwin-cpp.html">activeqt/opengl/globjwin.cpp</a></li>
<li><a href="activeqt-opengl-globjwin-h.html">activeqt/opengl/globjwin.h</a></li>
<li><a href="activeqt-opengl-main-cpp.html">activeqt/opengl/main.cpp</a></li>
<li><a href="activeqt-opengl-opengl-pro.html">activeqt/opengl/opengl.pro</a></li>
</ul>
<p>The OpenGL example demonstrates the use of the default factory and <a href="qaxfactory.html#isServer">QAxFactory::isServer</a>(), and the implementation of an additional COM interface using <a href="qaxbindable.html">QAxBindable</a> and <a href="qaxaggregated.html">QAxAggregated</a>. The server executable can run both as an ActiveX server and as a stand-alone application.</p>
<p>The ActiveX control in this example uses the QGlWidget class in Qt to render an OpenGL scene in an ActiveX. The control exposes a few methods to change the scene.</p>
<p>The application uses the default factory as provided by the QAXFACTORY_DEFAULT macro to expose the <tt>GLBox</tt> widget as an ActiveX control.</p>
<pre class="cpp"> <span class="preprocessor">#include &lt;QAxFactory&gt;</span>

 <a href="qaxfactory.html#QAXFACTORY_DEFAULT">QAXFACTORY_DEFAULT</a>( GLBox<span class="operator">,</span>
                     <span class="string">&quot;{5fd9c22e-ed45-43fa-ba13-1530bb6b03e0}&quot;</span><span class="operator">,</span>
                     <span class="string">&quot;{33b051af-bb25-47cf-a390-5cfd2987d26a}&quot;</span><span class="operator">,</span>
                     <span class="string">&quot;{8c996c29-eafa-46ac-a6f9-901951e765b5}&quot;</span><span class="operator">,</span>
                     <span class="string">&quot;{2c3c183a-eeda-41a4-896e-3d9c12c3577d}&quot;</span><span class="operator">,</span>
                     <span class="string">&quot;{83e16271-6480-45d5-aaf1-3f40b7661ae4}&quot;</span>
                   )</pre>
<p>The implementation of <tt>main</tt> initializes the <a href="qapplication.html">QApplication</a> object, and uses <tt>QAxFactory::isServer()</tt> to determine whether or not it is appropriate to create and show the application interface.</p>
<pre class="cpp"> <span class="comment">/*
   The main program is here.
 */</span>

 <span class="type">int</span> main( <span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span><span class="operator">*</span>argv )
 {
     <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>setColorSpec( <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>CustomColor );
     <span class="type"><a href="qapplication.html">QApplication</a></span> a(argc<span class="operator">,</span>argv);

     <span class="keyword">if</span> ( <span class="operator">!</span><span class="type"><a href="qglformat.html">QGLFormat</a></span><span class="operator">::</span>hasOpenGL() ) {
         <a href="qtglobal.html#qWarning">qWarning</a>( <span class="string">&quot;This system has no OpenGL support. Exiting.&quot;</span> );
         <span class="keyword">return</span> <span class="operator">-</span><span class="number">1</span>;
     }

     <span class="keyword">if</span> ( <span class="operator">!</span><span class="type"><a href="qaxfactory.html">QAxFactory</a></span><span class="operator">::</span>isServer() ) {
         GLObjectWindow w;
         w<span class="operator">.</span>resize( <span class="number">400</span><span class="operator">,</span> <span class="number">350</span> );
         w<span class="operator">.</span>show();
         <span class="keyword">return</span> a<span class="operator">.</span>exec();
     }
     <span class="keyword">return</span> a<span class="operator">.</span>exec();
 }</pre>
<p>The <tt>GLBox</tt> class inherits from both the <a href="qglwidget.html">QGLWidget</a> class to be able to render OpenGL, and from <a href="qaxbindable.html">QAxBindable</a>.</p>
<pre class="cpp"> <span class="preprocessor">#include &lt;QAxBindable&gt;</span>

 <span class="keyword">class</span> GLBox : <span class="keyword">public</span> <span class="type"><a href="qglwidget.html">QGLWidget</a></span><span class="operator">,</span>
               <span class="keyword">public</span> <span class="type"><a href="qaxbindable.html">QAxBindable</a></span>
 {
     Q_OBJECT</pre>
<p>The class reimplements the <a href="qaxbindable.html#createAggregate">QAxBindable::createAggregate</a>() function from <a href="qaxbindable.html">QAxBindable</a> to return the pointer to a <a href="qaxaggregated.html">QAxAggregated</a> object.</p>
<pre class="cpp"> <span class="keyword">public</span>:

     GLBox( <span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">*</span> parent<span class="operator">,</span> <span class="keyword">const</span> <span class="type">char</span><span class="operator">*</span> name <span class="operator">=</span> <span class="number">0</span> );
     <span class="operator">~</span>GLBox();

     <span class="type"><a href="qaxaggregated.html">QAxAggregated</a></span> <span class="operator">*</span>createAggregate();

 <span class="keyword">public</span> <span class="keyword">slots</span>:

     <span class="type">void</span>                setXRotation( <span class="type">int</span> degrees );</pre>
<p>The rest of the class declaration and the implementation of the OpenGL rendering is identical to the original &quot;box&quot; example.</p>
<p>The implementation file of the <tt>GLBox</tt> class includes the <tt>objsafe.h</tt> system header, in which the <tt>IObjectSafety</tt> COM interface is defined.</p>
<pre class="cpp"> <span class="preprocessor">#include &lt;objsafe.h&gt;</span></pre>
<p>A class <tt>ObjectSafetyImpl</tt> is declared using multiple inheritance to subclass the <a href="qaxaggregated.html">QAxAggregated</a> class, and to implement the IObjectSafety interface.</p>
<pre class="cpp"> <span class="keyword">class</span> ObjectSafetyImpl : <span class="keyword">public</span> <span class="type"><a href="qaxaggregated.html">QAxAggregated</a></span><span class="operator">,</span>
                          <span class="keyword">public</span> IObjectSafety
 {
 <span class="keyword">public</span>:</pre>
<p>The class declares a default constructor, and implements the queryInterface function to support the IObjectSafety interface.</p>
<pre class="cpp">     ObjectSafetyImpl() {}

     <span class="type">long</span> queryInterface( <span class="keyword">const</span> <span class="type"><a href="quuid.html">QUuid</a></span> <span class="operator">&amp;</span>iid<span class="operator">,</span> <span class="type">void</span> <span class="operator">*</span><span class="operator">*</span>iface )
     {
         <span class="operator">*</span>iface <span class="operator">=</span> <span class="number">0</span>;
         <span class="keyword">if</span> ( iid <span class="operator">=</span><span class="operator">=</span> IID_IObjectSafety )
             <span class="operator">*</span>iface <span class="operator">=</span> (IObjectSafety<span class="operator">*</span>)<span class="keyword">this</span>;
         <span class="keyword">else</span>
             <span class="keyword">return</span> E_NOINTERFACE;

         AddRef();
         <span class="keyword">return</span> S_OK;
     }</pre>
<p>Since every COM interface inherits <tt>IUnknown</tt> the <tt>QAXAGG_IUNKNOWN</tt> macro is used to provide the default implementation of the <tt>IUnknown</tt> interface. The macro is defined to delegate all calls to <tt>QueryInterface</tt>, <tt>AddRef</tt> and <tt>Release</tt> to the interface returned by the controllingUnknown() function.</p>
<pre class="cpp">     QAXAGG_IUNKNOWN;</pre>
<p>The implementation of the <tt>IObjectSafety</tt> interface provides the caller with information about supported and enabled safety options, and returns <tt>S_OK</tt> for all calls to indicate that the ActiveX control is safe.</p>
<pre class="cpp">     HRESULT WINAPI GetInterfaceSafetyOptions( REFIID riid<span class="operator">,</span> DWORD <span class="operator">*</span>pdwSupportedOptions<span class="operator">,</span> DWORD <span class="operator">*</span>pdwEnabledOptions )
     {
         <span class="operator">*</span>pdwSupportedOptions <span class="operator">=</span> INTERFACESAFE_FOR_UNTRUSTED_DATA <span class="operator">|</span> INTERFACESAFE_FOR_UNTRUSTED_CALLER;
         <span class="operator">*</span>pdwEnabledOptions <span class="operator">=</span> INTERFACESAFE_FOR_UNTRUSTED_DATA <span class="operator">|</span> INTERFACESAFE_FOR_UNTRUSTED_CALLER;
         <span class="keyword">return</span> S_OK;
     }
     HRESULT WINAPI SetInterfaceSafetyOptions( REFIID riid<span class="operator">,</span> DWORD pdwSupportedOptions<span class="operator">,</span> DWORD pdwEnabledOptions )
     {
         <span class="keyword">return</span> S_OK;
     }
 };</pre>
<p>The implementation of the <tt>createAggregate()</tt> function just returns a new <tt>ObjectSafetyImpl</tt> object.</p>
<pre class="cpp"> <span class="type"><a href="qaxaggregated.html">QAxAggregated</a></span> <span class="operator">*</span>GLBox<span class="operator">::</span>createAggregate()
 {
     <span class="keyword">return</span> <span class="keyword">new</span> ObjectSafetyImpl();
 }</pre>
<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/wrapper</tt>.</p>
<p>The <a href="qaxserver-demo-opengl.html">demonstration</a> requires your WebBrowser to support ActiveX controls, and scripting to be enabled.</p>
<p>In contrast to the other <a href="qaxserver.html">QAxServer</a> examples Internet Explorer will not open a dialog box to ask the user whether or not the scripting of the GLBox control should be allowed (the exact browser behaviour depends on the security settings in the Internet Options dialog).</p>
<pre class="cpp"> &lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;
 function setRot( form )
 {
     GLBox.setXRotation( form.XEdit.value );
     GLBox.setYRotation( form.YEdit.value );
     GLBox.setZRotation( form.ZEdit.value );
 }
 &lt;/SCRIPT&gt;

 &lt;p /&gt;
 An OpenGL scene:&lt;br /&gt;
 &lt;object ID=&quot;GLBox&quot; CLASSID=&quot;CLSID:5fd9c22e-ed45-43fa-ba13-1530bb6b03e0&quot;
 CODEBASE=&quot;http://qt.nokia.com/demos/openglax.cab&quot;&gt;
 [Object not available! Did you forget to build and register the server?]
 &lt;/object&gt;&lt;br /&gt;

 &lt;form&gt;
 Rotate the scene:&lt;br /&gt;
 X:&lt;input type=&quot;edit&quot; ID=&quot;XEdit&quot; value=&quot;0&quot; /&gt;&lt;br /&gt;
 Y:&lt;input type=&quot;edit&quot; name=&quot;YEdit&quot; value=&quot;0&quot; /&gt;&lt;br /&gt;
 Z:&lt;input type=&quot;edit&quot; name=&quot;ZEdit&quot; value=&quot;0&quot; /&gt;&lt;br /&gt;
 &lt;input type=&quot;button&quot; value=&quot;Set&quot; onClick=&quot;setRot(this.form)&quot; /&gt;
 &lt;/form&gt;</pre>
</div>
<!-- @@@activeqt/opengl -->
  <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>