source: trunk/doc/html/qaxserver-example-tetrax.html

Last change on this file was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 5.5 KB
Line 
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/tetrax/tetrax.doc:27 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>A Qt example as a scriptable ActiveX control (executable)</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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>A Qt example as a scriptable ActiveX control (executable)</h1>
33
34
35
36This example shows how to turn an existing Qt application
37into an ActiveX control server. The ActiveX control is based
38on the Qt tetrix example.
39<p> It demonstrates the use of the default factory provied by the
40<a href="qaxfactory.html#QAXFACTORY_DEFAULT">QAXFACTORY_DEFAULT</a> macro, and of <a href="qaxfactory.html#isServer">QAxFactory::isServer</a>().
41<p> The code changes for the tetrix GUI are minimal (a property <tt>score</tt>,
42a signal <tt>gameOver</tt> and a slot <tt>startGame</tt>) and provide a better scripting
43interface for the use of the control in a web environment.
44<p> The implementation of the ActiveX server functionality is only in the
45tetrax.cpp file.
46
47
48The default implementation of the <a href="qaxfactory.html">QAxFactory</a> is used through the
49QAXFACTORY_DEFAULT macro, and exports the QTetrax object specifying
50the five unique IDs required by COM to instantiate and communicate with
51the server.
52<pre> #include "qtetrax.h"
53 #include "qdragapp.h"
54 #include "qfont.h"
55
56 #include &lt;<a href="qaxfactory-h.html">qaxfactory.h</a>&gt;
57
58 QAXFACTORY_DEFAULT( QTetrax,
59 "{852558AD-CBD6-4f07-844C-D1E8983CD6FC}",
60 "{2F5D0068-772C-4d1e-BCD2-D3F6BC7FD315}",
61 "{769F4820-9F28-490f-BA50-5545BD381DCB}",
62 "{5753B1A8-53B9-4abe-8690-6F14EC5CA8D0}",
63 "{DE2F7CE3-CFA7-4938-A9FC-867E2FEB63BA}" )
64</pre>The <tt>main</tt> entry point method instantiates a <a href="qapplication.html">QApplication</a> object, and
65creates the GUI only if the program is not running as an ActiveX server (ie.
66the program has been started by the user, not by COM).
67<pre> int main( int argc, char **argv )
68 {
69 <a name="x2716"></a> QApplication::<a href="qapplication.html#setColorSpec">setColorSpec</a>( QApplication::CustomColor );
70 QDragApplication a(argc,argv);
71
72 QTetrax *tetrax = 0;
73 if ( !QAxFactory::isServer() ) {
74 tetrax = new QTetrax;
75 <a name="x2718"></a> tetrax-&gt;<a href="qwidget.html#setCaption">setCaption</a>("Tetrax");
76 a.<a href="qapplication.html#setMainWidget">setMainWidget</a>(tetrax);
77 tetrax-&gt;<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Tetrax");
78 tetrax-&gt;<a href="qwidget.html#show">show</a>();
79 }
80</pre>The server enters the application event loop, and destroys the GUI before exiting.
81<pre> int res = a.<a href="qapplication.html#exec">exec</a>();
82 delete tetrax;
83 return res;
84 }
85</pre>
86<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
87<tt>examples/tetrix</tt>.
88<p> <hr>
89<p> The <a href="qaxserver-demo-tetrax.html">demonstration</a> requires your
90Web browser to support ActiveX controls, and scripting to be enabled.
91<p>
92
93The "Tetrix" control is embedded using the <tt>&lt;object&gt;</tt> tag. Note that the
94dimensions of the control are provided explicitely, as the control itself
95does not use Qt's layout engine.
96<pre> &lt;object ID="QTetrax" width=550 height=370
97 CLASSID="CLSID:852558AD-CBD6-4f07-844C-D1E8983CD6FC"
98 CODEBASE=http://www.trolltech.com/demos/tetrax.cab&gt;
99 &lt;PARAM NAME="score" VALUE="0"&gt;
100 [Object not available! Did you forget to build and register the server?]
101 &lt;/object&gt;
102</pre>An HTML button is added to start the game.
103<pre> &lt;form&gt;
104 &lt;input type="button" value="Start Game..."
105 onClick="QTetrax.startGame()"&gt;
106 &lt;/form&gt;
107</pre>And an event handler for the <tt>gameOver()</tt> event is implemented in JavaScript
108to display a simple message box.
109<pre> &lt;SCRIPT LANGUAGE=JavaScript&gt;
110 function QTetrax::gameOver()
111 {
112 alert( "GameOver!" );
113 }
114 &lt;/SCRIPT&gt;
115</pre><p>See also <a href="qaxserver-examples.html">The QAxServer Examples</a>.
116
117<!-- eof -->
118<p><address><hr><div align=center>
119<table width=100% cellspacing=0 border=0><tr>
120<td>Copyright &copy; 2007
121<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
122<td align=right><div align=right>Qt 3.3.8</div>
123</table></div></address></body>
124</html>
Note: See TracBrowser for help on using the repository browser.