Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > ff187cb994c94c614ecc64c5a8528b1b > files > 35

qt-doc-4.8.5-10.fc18.noarch.rpm

<?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/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <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 class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></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>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc 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>
      Digia, Qt and their respective logos are trademarks of Digia Plc 
      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>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>