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

# A simple ActiveTQt control (executable)

The ActiveX control in this example is a layouted TQWidget with a TQSlider, a TQLCDNumber and a TQLineEdit. It provides a signal/slot/property interface to change the values of the slider and the line edit, and to get notified of any property changes.

It demonstrates the use of TQAxBindable::requestPropertyChange() and TQAxBindable::propertyChanged(), and the use of the default TQAxFactory through the TQAXFACTORY_DEFAULT macro.

The TQt implementation of the ActiveX for this example is

        class TQSimpleAX : public TQWidget, public TQAxBindable
        {
            TQ_OBJECT
            TQ_PROPERTY( TQString text READ text WRITE setText )
            TQ_PROPERTY( int value READ value WRITE setValue )
        public:
            TQSimpleAX( TQWidget *parent = 0, const char *name = 0 )
            : TQWidget( parent, name )
            {
                TQVBoxLayout *vbox = new TQVBoxLayout( this );

                slider = new TQSlider( 0, 100, 1, 0, TQSlider::Horizontal, this );
                LCD = new TQLCDNumber( 3, this );
                edit = new TQLineEdit( this );

                connect( slider, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SLOT( setValue(int) ) );
                connect( edit, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(setText(const TQString&)) );

                vbox->addWidget( slider );
                vbox->addWidget( LCD );
                vbox->addWidget( edit );
            }

            TQString text() const
            {
                return edit->text();
            }
            int value() const
            {
                return slider->value();
            }

        signals:
            void someSignal();
            void valueChanged(int);
            void textChanged(const TQString&);

        public slots:
            void setText( const TQString &string )
            {
                if ( !requestPropertyChange( "text" ) )
                    return;

                edit->blockSignals( TRUE );
                edit->setText( string );
                edit->blockSignals( FALSE );
                emit someSignal();
                emit textChanged( string );

                propertyChanged( "text" );
            }
            void about()
            {
                TQMessageBox::information( this, "About TQSimpleAX", "This is a TQt widget, and this slot has been\n"
                                                                  "called through ActiveX/OLE automation!" );
            }
            void setValue( int i )
            {
                if ( !requestPropertyChange( "value" ) )
                    return;
                slider->blockSignals( TRUE );
                slider->setValue( i );
                slider->blockSignals( FALSE );
                LCD->display( i );
                emit valueChanged( i );

                propertyChanged( "value" );
            }

        private:
            TQSlider *slider;
            TQLCDNumber *LCD;
            TQLineEdit *edit;
        };

The control is exported using the default TQAxFactory

        TQAXFACTORY_DEFAULT(TQSimpleAX,
                   "{DF16845C-92CD-4AAB-A982-EB9840E74669}",
                   "{616F620B-91C5-4410-A74E-6B81C76FFFE0}",
                   "{E1816BBA-BF5D-4A31-9855-D6BA432055FF}",
                   "{EC08F8FC-2754-47AB-8EFE-56A54057F34E}",
                   "{A095BA0C-224F-4933-A458-2DD7F6B85D8F}")

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

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

The simple ActiveX control is embedded using the `<object>` tag.

        <object ID="TQSimpleAX" CLASSID="CLSID:DF16845C-92CD-4AAB-A982-EB9840E74669"
        CODEBASE=http://www.trolltech.com/demos/simpleax.cab>
            <PARAM NAME="text" VALUE="A simple control">
            <PARAM NAME="value" VALUE="1">
        [Object not available! Did you forget to build and register the server?]
        </object>

A simple HTML button is connected to the ActiveTQt's about() slot.

        <FORM>
            <INPUT TYPE="BUTTON" VALUE="About..." onClick="TQSimpleAX.about()">
        </FORM>

A second ActiveX control - the standard Calendar Control - is instantiated

        <object ID="Calendar" CLASSID="CLSID:8E27C92B-1264-101C-8A2F-040224009C02">
        [Standard Calendar control not available!]
            <PARAM NAME="day" VALUE="1">
        </object>

Events from the ActiveX controls are handled using both Visual Basic Script and JavaScript.

        <SCRIPT LANGUAGE=VBScript>
        Sub Calendar_Click()
            MsgBox( "Calendar Clicked!" )
        End Sub

        Sub TQSimpleAX_TextChanged( str )
            document.title = str
        End Sub
        </SCRIPT>
        <SCRIPT LANGUAGE=JavaScript>
        function TQSimpleAX::ValueChanged( Newvalue )
        {
            Calendar.Day = Newvalue;
        }
        </SCRIPT>

See also The TQAxServer Examples.