[190] | 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"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { 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 Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main 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 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 |
|
---|
| 36 | This example shows how to turn an existing Qt application
|
---|
| 37 | into an ActiveX control server. The ActiveX control is based
|
---|
| 38 | on 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>,
|
---|
| 42 | a signal <tt>gameOver</tt> and a slot <tt>startGame</tt>) and provide a better scripting
|
---|
| 43 | interface for the use of the control in a web environment.
|
---|
| 44 | <p> The implementation of the ActiveX server functionality is only in the
|
---|
| 45 | tetrax.cpp file.
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | The default implementation of the <a href="qaxfactory.html">QAxFactory</a> is used through the
|
---|
| 49 | QAXFACTORY_DEFAULT macro, and exports the QTetrax object specifying
|
---|
| 50 | the five unique IDs required by COM to instantiate and communicate with
|
---|
| 51 | the server.
|
---|
| 52 | <pre> #include "qtetrax.h"
|
---|
| 53 | #include "qdragapp.h"
|
---|
| 54 | #include "qfont.h"
|
---|
| 55 |
|
---|
| 56 | #include <<a href="qaxfactory-h.html">qaxfactory.h</a>>
|
---|
| 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
|
---|
| 65 | creates the GUI only if the program is not running as an ActiveX server (ie.
|
---|
| 66 | the 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-><a href="qwidget.html#setCaption">setCaption</a>("Tetrax");
|
---|
| 76 | a.<a href="qapplication.html#setMainWidget">setMainWidget</a>(tetrax);
|
---|
| 77 | tetrax-><a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Tetrax");
|
---|
| 78 | tetrax-><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
|
---|
| 90 | Web browser to support ActiveX controls, and scripting to be enabled.
|
---|
| 91 | <p>
|
---|
| 92 |
|
---|
| 93 | The "Tetrix" control is embedded using the <tt><object></tt> tag. Note that the
|
---|
| 94 | dimensions of the control are provided explicitely, as the control itself
|
---|
| 95 | does not use Qt's layout engine.
|
---|
| 96 | <pre> <object ID="QTetrax" width=550 height=370
|
---|
| 97 | CLASSID="CLSID:852558AD-CBD6-4f07-844C-D1E8983CD6FC"
|
---|
| 98 | CODEBASE=http://www.trolltech.com/demos/tetrax.cab>
|
---|
| 99 | <PARAM NAME="score" VALUE="0">
|
---|
| 100 | [Object not available! Did you forget to build and register the server?]
|
---|
| 101 | </object>
|
---|
| 102 | </pre>An HTML button is added to start the game.
|
---|
| 103 | <pre> <form>
|
---|
| 104 | <input type="button" value="Start Game..."
|
---|
| 105 | onClick="QTetrax.startGame()">
|
---|
| 106 | </form>
|
---|
| 107 | </pre>And an event handler for the <tt>gameOver()</tt> event is implemented in JavaScript
|
---|
| 108 | to display a simple message box.
|
---|
| 109 | <pre> <SCRIPT LANGUAGE=JavaScript>
|
---|
| 110 | function QTetrax::gameOver()
|
---|
| 111 | {
|
---|
| 112 | alert( "GameOver!" );
|
---|
| 113 | }
|
---|
| 114 | </SCRIPT>
|
---|
| 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 © 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>
|
---|