Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 1dd17e0d683ef79b4bb6872bbf359d7f > files > 9

qt4-doc-4.8.7-26.2.mga7.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" />
<!-- comapp.qdoc -->
  <title>Qt 4.8: COM App 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>COM App 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">COM App Example (ActiveQt)</h1>
<span class="subtitle"></span>
<!-- $$$activeqt/comapp-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="activeqt-comapp-main-cpp.html">activeqt/comapp/main.cpp</a></li>
<li><a href="activeqt-comapp-comapp-pro.html">activeqt/comapp/comapp.pro</a></li>
</ul>
<p>The COM App example shows how to use <a href="activeqt.html#activeqt">ActiveQt</a> to develop a Qt application that can be automated via COM.<p>Different <a href="qobject.html">QObject</a> based classes are exposed as COM objects that communicate with the GUI of the running Qt application. The APIs of those COM objects has been designed to resemble the APIs of standard COM applications; i.e&#x2e; those from Microsoft Office.</p>
<pre class="cpp"> <span class="keyword">class</span> Application : <span class="keyword">public</span> <span class="type"><a href="qobject.html">QObject</a></span>
 {
     Q_OBJECT

     Q_CLASSINFO(<span class="string">&quot;ClassID&quot;</span><span class="operator">,</span> <span class="string">&quot;{b50a71db-c4a7-4551-8d14-49983566afee}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;InterfaceID&quot;</span><span class="operator">,</span> <span class="string">&quot;{4a427759-16ef-4ed8-be79-59ffe5789042}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;RegisterObject&quot;</span><span class="operator">,</span> <span class="string">&quot;yes&quot;</span>)

     Q_PROPERTY(DocumentList<span class="operator">*</span> documents READ documents)
     Q_PROPERTY(<span class="type"><a href="qstring.html">QString</a></span> id READ id)
     Q_PROPERTY(<span class="type">bool</span> visible READ isVisible WRITE setVisible)

 <span class="keyword">public</span>:
     Application(<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>);
     DocumentList <span class="operator">*</span>documents() <span class="keyword">const</span>;

     <span class="type"><a href="qstring.html">QString</a></span> id() <span class="keyword">const</span> { <span class="keyword">return</span> objectName(); }

     <span class="type">void</span> setVisible(<span class="type">bool</span> on);
     <span class="type">bool</span> isVisible() <span class="keyword">const</span>;

     <span class="type"><a href="qtabwidget.html">QTabWidget</a></span> <span class="operator">*</span>window() <span class="keyword">const</span> { <span class="keyword">return</span> ui; }

 <span class="keyword">public</span> <span class="keyword">slots</span>:
     <span class="type">void</span> quit();

 <span class="keyword">private</span>:
     DocumentList <span class="operator">*</span>docs;

     <span class="type"><a href="qtabwidget.html">QTabWidget</a></span> <span class="operator">*</span>ui;
 };</pre>
<p>The first class <tt>Application</tt> represents the application object. It exposes read-only properties <tt>documents</tt> and <tt>id</tt> to get access to the list of documents, and an identifier. A read/write property <tt>visible</tt> controls whether the <a href="qtabwidget.html">QTabWidget</a>-based user interface of the application should be visible, and a slot <tt>quit()</tt> terminates the application.</p>
<p>The <i>RegisterObject</i> attribute is set to make sure that instances of this class are registered in COM's running object table (ROT) - this allows COM clients to connect to an already instantiated COM object.</p>
<pre class="cpp"> <span class="keyword">class</span> DocumentList : <span class="keyword">public</span> <span class="type"><a href="qobject.html">QObject</a></span>
 {
     Q_OBJECT

     Q_CLASSINFO(<span class="string">&quot;ClassID&quot;</span><span class="operator">,</span> <span class="string">&quot;{496b761d-924b-4554-a18a-8f3704d2a9a6}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;InterfaceID&quot;</span><span class="operator">,</span> <span class="string">&quot;{6c9e30e8-3ff6-4e6a-9edc-d219d074a148}&quot;</span>)

     Q_PROPERTY(Application<span class="operator">*</span> application READ application)
     Q_PROPERTY(<span class="type">int</span> count READ count)

 <span class="keyword">public</span>:
     DocumentList(Application <span class="operator">*</span>application);

     <span class="type">int</span> count() <span class="keyword">const</span>;
     Application <span class="operator">*</span>application() <span class="keyword">const</span>;

 <span class="keyword">public</span> <span class="keyword">slots</span>:
     Document <span class="operator">*</span>addDocument();
     Document <span class="operator">*</span>item(<span class="type">int</span> index) <span class="keyword">const</span>;

 <span class="keyword">private</span>:
     <span class="type"><a href="qlist.html">QList</a></span><span class="operator">&lt;</span>Document<span class="operator">*</span><span class="operator">&gt;</span> list;
 };</pre>
<p>The <tt>DocumentList</tt> class stores a list of documents. It provides an API to read the number of documents, to access each document by index and to create a new document. The <tt>application</tt> property returns the root object.</p>
<pre class="cpp"> <span class="keyword">class</span> Document : <span class="keyword">public</span> <span class="type"><a href="qobject.html">QObject</a></span>
 {
     Q_OBJECT

     Q_CLASSINFO(<span class="string">&quot;ClassID&quot;</span><span class="operator">,</span> <span class="string">&quot;{2b5775cd-72c2-43da-bc3b-b0e8d1e1c4f7}&quot;</span>)
     Q_CLASSINFO(<span class="string">&quot;InterfaceID&quot;</span><span class="operator">,</span> <span class="string">&quot;{2ce1761e-07a3-415c-bd11-0eab2c7283de}&quot;</span>)

     Q_PROPERTY(Application <span class="operator">*</span>application READ application)
     Q_PROPERTY(<span class="type"><a href="qstring.html">QString</a></span> title READ title WRITE setTitle)

 <span class="keyword">public</span>:
     Document(DocumentList <span class="operator">*</span>list);
     <span class="operator">~</span>Document();

     Application <span class="operator">*</span>application() <span class="keyword">const</span>;

     <span class="type"><a href="qstring.html">QString</a></span> title() <span class="keyword">const</span>;
     <span class="type">void</span> setTitle(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>title);

 <span class="keyword">private</span>:
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>page;
 };</pre>
<p>The <tt>Document</tt> class finally represents a document in the application. Each document is represented by a page in the application's tab widget, and has a title that is readable and writable through the document's API. The <tt>application</tt> property again returns the root object.</p>
<pre class="cpp"> Document<span class="operator">::</span>Document(DocumentList <span class="operator">*</span>list)
 : <span class="type"><a href="qobject.html">QObject</a></span>(list)
 {
     <span class="type"><a href="qtabwidget.html">QTabWidget</a></span> <span class="operator">*</span>tabs <span class="operator">=</span> list<span class="operator">-</span><span class="operator">&gt;</span>application()<span class="operator">-</span><span class="operator">&gt;</span>window();
     page <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>(tabs);
     page<span class="operator">-</span><span class="operator">&gt;</span>setWindowTitle(<span class="string">&quot;Unnamed&quot;</span>);
     tabs<span class="operator">-</span><span class="operator">&gt;</span>addTab(page<span class="operator">,</span> page<span class="operator">-</span><span class="operator">&gt;</span>windowTitle());

     page<span class="operator">-</span><span class="operator">&gt;</span>show();
 }

 Document<span class="operator">::</span><span class="operator">~</span>Document()
 {
     <span class="keyword">delete</span> page;
 }

 Application <span class="operator">*</span>Document<span class="operator">::</span>application() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> qobject_cast<span class="operator">&lt;</span>DocumentList<span class="operator">*</span><span class="operator">&gt;</span>(parent())<span class="operator">-</span><span class="operator">&gt;</span>application();
 }

 <span class="type"><a href="qstring.html">QString</a></span> Document<span class="operator">::</span>title() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> page<span class="operator">-</span><span class="operator">&gt;</span>windowTitle();
 }

 <span class="type">void</span> Document<span class="operator">::</span>setTitle(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>t)
 {
     page<span class="operator">-</span><span class="operator">&gt;</span>setWindowTitle(t);

     <span class="type"><a href="qtabwidget.html">QTabWidget</a></span> <span class="operator">*</span>tabs <span class="operator">=</span> application()<span class="operator">-</span><span class="operator">&gt;</span>window();
     <span class="type">int</span> index <span class="operator">=</span> tabs<span class="operator">-</span><span class="operator">&gt;</span>indexOf(page);
     tabs<span class="operator">-</span><span class="operator">&gt;</span>setTabText(index<span class="operator">,</span> page<span class="operator">-</span><span class="operator">&gt;</span>windowTitle());
 }</pre>
<p>The implementation of the <tt>Document</tt> class creates a new page for the tab widget, and uses the title of that page for the title property. The page is deleted when the document is deleted.</p>
<pre class="cpp"> DocumentList<span class="operator">::</span>DocumentList(Application <span class="operator">*</span>application)
 : <span class="type"><a href="qobject.html">QObject</a></span>(application)
 {
 }

 Application <span class="operator">*</span>DocumentList<span class="operator">::</span>application() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> qobject_cast<span class="operator">&lt;</span>Application<span class="operator">*</span><span class="operator">&gt;</span>(parent());
 }

 <span class="type">int</span> DocumentList<span class="operator">::</span>count() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> list<span class="operator">.</span>count();
 }

 Document <span class="operator">*</span>DocumentList<span class="operator">::</span>item(<span class="type">int</span> index) <span class="keyword">const</span>
 {
     <span class="keyword">if</span> (index <span class="operator">&gt;</span><span class="operator">=</span> list<span class="operator">.</span>count())
         <span class="keyword">return</span> <span class="number">0</span>;

     <span class="keyword">return</span> list<span class="operator">.</span>at(index);
 }

 Document <span class="operator">*</span>DocumentList<span class="operator">::</span>addDocument()
 {
     Document <span class="operator">*</span>document <span class="operator">=</span> <span class="keyword">new</span> Document(<span class="keyword">this</span>);
     list<span class="operator">.</span>append(document);

     <span class="keyword">return</span> document;
 }</pre>
<p>The <tt>DocumentList</tt> implementation is straightforward.</p>
<pre class="cpp"> Application<span class="operator">::</span>Application(<span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>parent)
 : <span class="type"><a href="qobject.html">QObject</a></span>(parent)<span class="operator">,</span> ui(<span class="number">0</span>)
 {
     ui <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtabwidget.html">QTabWidget</a></span>;

     setObjectName(<span class="string">&quot;From QAxFactory&quot;</span>);
     docs <span class="operator">=</span> <span class="keyword">new</span> DocumentList(<span class="keyword">this</span>);
 }

 DocumentList <span class="operator">*</span>Application<span class="operator">::</span>documents() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> docs;
 }

 <span class="type">void</span> Application<span class="operator">::</span>setVisible(<span class="type">bool</span> on)
 {
     ui<span class="operator">-</span><span class="operator">&gt;</span>setShown(on);
 }

 <span class="type">bool</span> Application<span class="operator">::</span>isVisible() <span class="keyword">const</span>
 {
     <span class="keyword">return</span> ui<span class="operator">-</span><span class="operator">&gt;</span>isVisible();
 }

 <span class="type">void</span> Application<span class="operator">::</span>quit()
 {
     <span class="keyword">delete</span> docs;
     docs <span class="operator">=</span> <span class="number">0</span>;

     <span class="keyword">delete</span> ui;
     ui <span class="operator">=</span> <span class="number">0</span>;
     <span class="type"><a href="qtimer.html">QTimer</a></span><span class="operator">::</span>singleShot(<span class="number">0</span><span class="operator">,</span> qApp<span class="operator">,</span> SLOT(quit()));
 }

 <span class="preprocessor">#include &quot;main.moc&quot;</span></pre>
<p>The <tt>Application</tt> class initializes the user interface in the constructor, and shows and hides it in the implementation of <tt>setVisible()</tt>. The object name (accessible through the <tt>id</tt> property) is set to <tt>&quot;From</tt> <a href="qaxfactory.html">QAxFactory</a>&quot; to indicate that this COM object has been created by COM. Note that there is no destructor that would delete the <a href="qtabwidget.html">QTabWidget</a> - this is instead done in the <tt>quit()</tt> slot, before calling <a href="qcoreapplication.html#quit">QApplication::quit</a>() through a single-shot-timer, which is necessary ensure that the COM call to the slot is complete.</p>
<pre class="cpp"> <a href="qaxfactory.html#QAXFACTORY_BEGIN">QAXFACTORY_BEGIN</a>(<span class="string">&quot;{edd3e836-f537-4c6f-be7d-6014c155cc7a}&quot;</span><span class="operator">,</span> <span class="string">&quot;{b7da3de8-83bb-4bbe-9ab7-99a05819e201}&quot;</span>)
    <a href="qaxfactory.html#QAXCLASS">QAXCLASS</a>(Application)
    <a href="qaxfactory.html#QAXTYPE">QAXTYPE</a>(Document)
    <a href="qaxfactory.html#QAXTYPE">QAXTYPE</a>(DocumentList)
 <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. Only <tt>Application</tt> objects can be instantiated from outside - the other APIs can only be used after accessing the respective objects throught the <tt>Application</tt> API.</p>
<pre class="cpp"> <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> app(argc<span class="operator">,</span> argv);
     app<span class="operator">.</span>setQuitOnLastWindowClosed(<span class="keyword">false</span>);

     <span class="comment">// started by COM - don't do anything</span>
     <span class="keyword">if</span> (<span class="type"><a href="qaxfactory.html">QAxFactory</a></span><span class="operator">::</span>isServer())
         <span class="keyword">return</span> app<span class="operator">.</span>exec();

     <span class="comment">// started by user</span>
     Application appobject(<span class="number">0</span>);
     appobject<span class="operator">.</span>setObjectName(<span class="string">&quot;From Application&quot;</span>);

     <span class="type"><a href="qaxfactory.html">QAxFactory</a></span><span class="operator">::</span>startServer();
     <span class="type"><a href="qaxfactory.html">QAxFactory</a></span><span class="operator">::</span>registerActiveObject(<span class="operator">&amp;</span>appobject);

     appobject<span class="operator">.</span>setVisible(<span class="keyword">true</span>);

     <span class="type"><a href="qobject.html">QObject</a></span><span class="operator">::</span>connect(qApp<span class="operator">,</span> SIGNAL(lastWindowClosed())<span class="operator">,</span> <span class="operator">&amp;</span>appobject<span class="operator">,</span> SLOT(quit()));

     <span class="keyword">return</span> app<span class="operator">.</span>exec();
 }</pre>
<p>The main() entry point function creates a <a href="qapplication.html">QApplication</a>, and just enters the event loop if the application has been started by COM. If the application has been started by the user, then the <tt>Application</tt> object is created and the object name is set to &quot;From Application&quot;. Then the COM server is started, and the application object is registered with COM. It is now accessible to COM clients through the client-specific APIs.</p>
<p>Application exiting is controlled explicitly - if COM started the application, then the client code has to call quit(); if the user started the application, then the application terminates when the last window has been closed.</p>
<p>Finally, the user interface is made visible, and the event loop is started.</p>
<p>A simple Visual Basic application could now access this Qt application. In VB, start a new &quot;Standard Exe&quot; project and add a project reference to the comappLib type library. Create a form with a listbox &quot;DocumentList&quot;, a static label &quot;DocumentsCount&quot; and a command button &quot;NewDocument&quot;. Finally, implement the code for the form like this:</p>
<pre class="cpp"> Private Application As comappLib.Application
 Private MyApp As Boolean

 Private Sub UpdateList()
     DocumentList.Clear
     DocumentsCount.Caption = Application.documents.Count
     For Index = 0 To Application.documents.Count - 1
        DocumentList.AddItem (Application.documents.Item(Index).Title)
     Next
 End Sub

 Private Sub Form_Load()
     On Error GoTo CreateNew
     Set Application = GetObject(, &quot;comapp.Application&quot;)
     MyApp = False
     GoTo Initialized
 CreateNew:
     On Error GoTo InitializeFailed
     Set Application = New Application
     Application.Visible = True
     MyApp = True
 Initialized:
     Caption = Application.id
     UpdateList
 InitializeFailed:
 End Sub

 Private Sub Form_Unload(Cancel As Integer)
     If MyApp Then
         Application.quit
     End If
 End Sub

 Private Sub NewDocument_Click()
     Application.documents.addDocument
     UpdateList
 End Sub</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\comapp</tt>.</p>
</div>
<!-- @@@activeqt/comapp -->
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </div>
  </div> 
  <div class="footer">
    <p>
      <acronym title="Copyright">&copy;</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>