<?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/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 & 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> 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 & 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>Multiple 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">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">"ClassID"</span><span class="operator">,</span> <span class="string">"{1D9928BD-4453-4bdd-903D-E525ED17FDE5}"</span>) Q_CLASSINFO(<span class="string">"InterfaceID"</span><span class="operator">,</span> <span class="string">"{99F6860E-2C5A-42ec-87F2-43396F4BE389}"</span>) Q_CLASSINFO(<span class="string">"EventsID"</span><span class="operator">,</span> <span class="string">"{0A3E9F27-E4F1-45bb-9E47-63099BCCD0E3}"</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">&</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">"ClassID"</span><span class="operator">,</span> <span class="string">"{58139D56-6BE9-4b17-937D-1B1EDEDD5B71}"</span>) Q_CLASSINFO(<span class="string">"InterfaceID"</span><span class="operator">,</span> <span class="string">"{B66280AB-08CC-4dcc-924F-58E6D7975B7D}"</span>) Q_CLASSINFO(<span class="string">"EventsID"</span><span class="operator">,</span> <span class="string">"{D72BACBA-03C4-4480-B4BB-DE4FE3AA14A0}"</span>) Q_CLASSINFO(<span class="string">"ToSuperClass"</span><span class="operator">,</span> <span class="string">"QAxWidget2"</span>) Q_CLASSINFO(<span class="string">"StockEvents"</span><span class="operator">,</span> <span class="string">"yes"</span>) Q_CLASSINFO(<span class="string">"Insertable"</span><span class="operator">,</span> <span class="string">"yes"</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 "ax1.h"</span> <span class="preprocessor">#include "ax2.h"</span> <span class="preprocessor">#include <QAxFactory></span> QT_USE_NAMESPACE <a href="qaxfactory.html#QAXFACTORY_BEGIN">QAXFACTORY_BEGIN</a>(<span class="string">"{98DE28B6-6CD3-4e08-B9FA-3D1DB43F1D2F}"</span><span class="operator">,</span> <span class="string">"{05828915-AD1C-47ab-AB96-D6AD1E25F0E2}"</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"> <script language="javascript"> function setColor( form ) { Ax1.fillColor = form.colorEdit.value; } function setWidth( form ) { Ax2.lineWidth = form.widthEdit.value; } </script> <p /> This is one QWidget subclass:<br /> <object ID="Ax1" CLASSID="CLSID:1D9928BD-4453-4bdd-903D-E525ED17FDE5" CODEBASE="http://qt.nokia.com/demos/multipleax.cab"> [Object not available! Did you forget to build and register the server?] </object><br /> <form> Fill Color: <input type="edit" ID="colorEdit" value = "red" /> <input type="button" value = "Set" onClick="setColor(this.form)" /> <input type="button" value = "Hide" onClick="Ax1.hide()" /> <input type="button" value = "Show" onClick="Ax1.show()" /> </form> <p /> This is another QWidget subclass:<br /> <object ID="Ax2" CLASSID="CLSID:58139D56-6BE9-4b17-937D-1B1EDEDD5B71" CODEBASE="http://qt.nokia.com/demos/multipleax.cab"> [Object not available! Did you forget to build and register the server?] </object><br /> <form> Line width: <input type="edit" ID="widthEdit" value = "1" /> <input type="button" value = "Set" onClick="setWidth(this.form)" /> </form></pre> </div> <!-- @@@activeqt/multiple --> </div> </div> </div> <div class="ft"> <span></span> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2015 The Qt Company Ltd. 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> Qt and respective logos are trademarks of The Qt Company Ltd 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>