Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

A TQt example as a scriptable ActiveX control (executable)

This example shows how to turn an existing TQt application into an ActiveX control server. The ActiveX control is based on the TQt tetrix example.

It demonstrates the use of the default factory provied by the TQAXFACTORY_DEFAULT macro, and of TQAxFactory::isServer().

The code changes for the tetrix GUI are minimal (a property score, a signal gameOver and a slot startGame) and provide a better scripting interface for the use of the control in a web environment.

The implementation of the ActiveX server functionality is only in the tetrax.cpp file. The default implementation of the TQAxFactory is used through the TQAXFACTORY_DEFAULT macro, and exports the TQTetrax object specifying the five unique IDs required by COM to instantiate and communicate with the server.

    #include "qtetrax.h"
    #include "qdragapp.h"
    #include "ntqfont.h"

    #include <qaxfactory.h>

                "{DE2F7CE3-CFA7-4938-A9FC-867E2FEB63BA}" )
The main entry point method instantiates a TQApplication object, and creates the GUI only if the program is not running as an ActiveX server (ie. the program has been started by the user, not by COM).
    int main( int argc, char **argv )
        TQApplication::setColorSpec( TQApplication::CustomColor );
        TQDragApplication a(argc,argv);

        TQTetrax *tetrax = 0;
        if ( !TQAxFactory::isServer() ) {
            tetrax = new TQTetrax;
            tetrax->setCaption("TQt Example - Tetrax");
The server enters the application event loop, and destroys the GUI before exiting.
        int res = a.exec();
        delete tetrax;
        return res;

To build the example you must first build the TQAxServer library. Then run qmake and your make tool in examples/tetrix.

The demonstration requires your Web browser to support ActiveX controls, and scripting to be enabled.

The "Tetrix" control is embedded using the <object> tag. Note that the dimensions of the control are provided explicitely, as the control itself does not use TQt's layout engine.

    <object ID="TQTetrax" width=550 height=370
        <PARAM NAME="score" VALUE="0">
    [Object not available! Did you forget to build and register the server?]
An HTML button is added to start the game.
        <input type="button" value="Start Game..."
And an event handler for the gameOver() event is implemented in JavaScript to display a simple message box.
    <SCRIPT LANGUAGE=JavaScript>
    function TQTetrax::gameOver()
        alert( "GameOver!" );

See also The TQAxServer Examples.

Copyright © 2007 TrolltechTrademarks
TQt 3.3.8