| 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/simple/simple.doc:45 --> | 
|---|
| 3 | <html> | 
|---|
| 4 | <head> | 
|---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|---|
| 6 | <title>A simple ActiveQt 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 simple ActiveQt control (executable)</h1> | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 |  | 
|---|
| 36 | The ActiveX control in this example is a layouted <a href="qwidget.html">QWidget</a> | 
|---|
| 37 | with a <a href="qslider.html">QSlider</a>, a <a href="qlcdnumber.html">QLCDNumber</a> and a <a href="qlineedit.html">QLineEdit</a>. | 
|---|
| 38 | It provides a signal/slot/property interface to change the | 
|---|
| 39 | values of the slider and the line edit, and to get notified | 
|---|
| 40 | of any property changes. | 
|---|
| 41 | <p> It demonstrates the use of <a href="qaxbindable.html#requestPropertyChange">QAxBindable::requestPropertyChange</a>() | 
|---|
| 42 | and <a href="qaxbindable.html#propertyChanged">QAxBindable::propertyChanged</a>(), and the use of the default | 
|---|
| 43 | <a href="qaxfactory.html">QAxFactory</a> through the <a href="qaxfactory.html#QAXFACTORY_DEFAULT">QAXFACTORY_DEFAULT</a> macro. | 
|---|
| 44 | <p> | 
|---|
| 45 |  | 
|---|
| 46 | <p> The Qt implementation of the ActiveX for this example is | 
|---|
| 47 | <pre>    class QSimpleAX : public <a href="qwidget.html">QWidget</a>, public QAxBindable | 
|---|
| 48 | { | 
|---|
| 49 | <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a> | 
|---|
| 50 | Q_PROPERTY( QString text READ text WRITE setText ) | 
|---|
| 51 | Q_PROPERTY( int value READ value WRITE setValue ) | 
|---|
| 52 | public: | 
|---|
| 53 | QSimpleAX( <a href="qwidget.html">QWidget</a> *parent = 0, const char *name = 0 ) | 
|---|
| 54 | : <a href="qwidget.html">QWidget</a>( parent, name ) | 
|---|
| 55 | { | 
|---|
| 56 | <a href="qvboxlayout.html">QVBoxLayout</a> *vbox = new <a href="qvboxlayout.html">QVBoxLayout</a>( this ); | 
|---|
| 57 |  | 
|---|
| 58 | slider = new <a href="qslider.html">QSlider</a>( 0, 100, 1, 0, QSlider::Horizontal, this ); | 
|---|
| 59 | LCD = new <a href="qlcdnumber.html">QLCDNumber</a>( 3, this ); | 
|---|
| 60 | edit = new <a href="qlineedit.html">QLineEdit</a>( this ); | 
|---|
| 61 |  | 
|---|
| 62 | <a name="x2528"></a>        connect( slider, SIGNAL( <a href="qslider.html#valueChanged">valueChanged</a>( int ) ), this, SLOT( setValue(int) ) ); | 
|---|
| 63 | <a name="x2523"></a>        connect( edit, SIGNAL(<a href="qlineedit.html#textChanged">textChanged</a>(const <a href="qstring.html">QString</a>&)), this, SLOT(setText(const <a href="qstring.html">QString</a>&)) ); | 
|---|
| 64 |  | 
|---|
| 65 | vbox-><a href="qboxlayout.html#addWidget">addWidget</a>( slider ); | 
|---|
| 66 | vbox-><a href="qboxlayout.html#addWidget">addWidget</a>( LCD ); | 
|---|
| 67 | vbox-><a href="qboxlayout.html#addWidget">addWidget</a>( edit ); | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | <a href="qstring.html">QString</a> text() const | 
|---|
| 71 | { | 
|---|
| 72 | <a name="x2522"></a>        return edit-><a href="qlineedit.html#text">text</a>(); | 
|---|
| 73 | } | 
|---|
| 74 | int value() const | 
|---|
| 75 | { | 
|---|
| 76 | <a name="x2527"></a>        return slider-><a href="qslider.html#value">value</a>(); | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | signals: | 
|---|
| 80 | void someSignal(); | 
|---|
| 81 | void valueChanged(int); | 
|---|
| 82 | void textChanged(const <a href="qstring.html">QString</a>&); | 
|---|
| 83 |  | 
|---|
| 84 | public slots: | 
|---|
| 85 | void setText( const <a href="qstring.html">QString</a> &string ) | 
|---|
| 86 | { | 
|---|
| 87 | if ( !requestPropertyChange( "text" ) ) | 
|---|
| 88 | return; | 
|---|
| 89 |  | 
|---|
| 90 | <a name="x2525"></a>        edit-><a href="qobject.html#blockSignals">blockSignals</a>( TRUE ); | 
|---|
| 91 | <a name="x2521"></a>        edit-><a href="qlineedit.html#setText">setText</a>( string ); | 
|---|
| 92 | edit-><a href="qobject.html#blockSignals">blockSignals</a>( FALSE ); | 
|---|
| 93 | emit someSignal(); | 
|---|
| 94 | emit textChanged( string ); | 
|---|
| 95 |  | 
|---|
| 96 | propertyChanged( "text" ); | 
|---|
| 97 | } | 
|---|
| 98 | void about() | 
|---|
| 99 | { | 
|---|
| 100 | <a name="x2524"></a>        QMessageBox::<a href="qmessagebox.html#information">information</a>( this, "About QSimpleAX", "This is a Qt widget, and this slot has been\n" | 
|---|
| 101 | "called through ActiveX/OLE automation!" ); | 
|---|
| 102 | } | 
|---|
| 103 | void setValue( int i ) | 
|---|
| 104 | { | 
|---|
| 105 | if ( !requestPropertyChange( "value" ) ) | 
|---|
| 106 | return; | 
|---|
| 107 | slider-><a href="qobject.html#blockSignals">blockSignals</a>( TRUE ); | 
|---|
| 108 | <a name="x2526"></a>        slider-><a href="qslider.html#setValue">setValue</a>( i ); | 
|---|
| 109 | slider-><a href="qobject.html#blockSignals">blockSignals</a>( FALSE ); | 
|---|
| 110 | LCD-><a href="qlcdnumber.html#display">display</a>( i ); | 
|---|
| 111 | emit valueChanged( i ); | 
|---|
| 112 |  | 
|---|
| 113 | propertyChanged( "value" ); | 
|---|
| 114 | } | 
|---|
| 115 |  | 
|---|
| 116 | private: | 
|---|
| 117 | <a href="qslider.html">QSlider</a> *slider; | 
|---|
| 118 | <a href="qlcdnumber.html">QLCDNumber</a> *LCD; | 
|---|
| 119 | <a href="qlineedit.html">QLineEdit</a> *edit; | 
|---|
| 120 | }; | 
|---|
| 121 | </pre> | 
|---|
| 122 | <p> The control is exported using the default <a href="qaxfactory.html">QAxFactory</a> | 
|---|
| 123 | <pre>    QAXFACTORY_DEFAULT(QSimpleAX, | 
|---|
| 124 | "{DF16845C-92CD-4AAB-A982-EB9840E74669}", | 
|---|
| 125 | "{616F620B-91C5-4410-A74E-6B81C76FFFE0}", | 
|---|
| 126 | "{E1816BBA-BF5D-4A31-9855-D6BA432055FF}", | 
|---|
| 127 | "{EC08F8FC-2754-47AB-8EFE-56A54057F34E}", | 
|---|
| 128 | "{A095BA0C-224F-4933-A458-2DD7F6B85D8F}") | 
|---|
| 129 | </pre> | 
|---|
| 130 | <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 | 
|---|
| 131 | <tt>examples/simple</tt>. | 
|---|
| 132 | <p> <hr> | 
|---|
| 133 | <p> The <a href="qaxserver-demo-simple.html">demonstration</a> requires your | 
|---|
| 134 | WebBrowser to support ActiveX controls, and scripting to be enabled. | 
|---|
| 135 | <p> The simple ActiveX control is embedded using the <tt><object></tt> tag. | 
|---|
| 136 |  | 
|---|
| 137 |  | 
|---|
| 138 | <pre>    <object ID="QSimpleAX" CLASSID="CLSID:DF16845C-92CD-4AAB-A982-EB9840E74669" | 
|---|
| 139 | CODEBASE=http://www.trolltech.com/demos/simpleax.cab> | 
|---|
| 140 | <PARAM NAME="text" VALUE="A simple control"> | 
|---|
| 141 | <PARAM NAME="value" VALUE="1"> | 
|---|
| 142 | [Object not available! Did you forget to build and register the server?] | 
|---|
| 143 | </object> | 
|---|
| 144 | </pre> | 
|---|
| 145 | <p> A simple HTML button is connected to the <a href="activeqt.html#ActiveQt">ActiveQt</a>'s about() slot. | 
|---|
| 146 | <pre>    <FORM> | 
|---|
| 147 | <INPUT TYPE="BUTTON" VALUE="About..." onClick="QSimpleAX.about()"> | 
|---|
| 148 | </FORM> | 
|---|
| 149 | </pre> | 
|---|
| 150 | <p> A second ActiveX control - the standard Calendar Control - is instantiated | 
|---|
| 151 | <pre>    <object ID="Calendar" CLASSID="CLSID:8E27C92B-1264-101C-8A2F-040224009C02"> | 
|---|
| 152 | [Standard Calendar control not available!] | 
|---|
| 153 | <PARAM NAME="day" VALUE="1"> | 
|---|
| 154 | </object> | 
|---|
| 155 | </pre> | 
|---|
| 156 | <p> Events from the ActiveX controls are handled using both Visual Basic Script | 
|---|
| 157 | and JavaScript. | 
|---|
| 158 | <pre>    <SCRIPT LANGUAGE=VBScript> | 
|---|
| 159 | Sub Calendar_Click() | 
|---|
| 160 | MsgBox( "Calendar Clicked!" ) | 
|---|
| 161 | End Sub | 
|---|
| 162 |  | 
|---|
| 163 | Sub QSimpleAX_TextChanged( str ) | 
|---|
| 164 | document.title = str | 
|---|
| 165 | End Sub | 
|---|
| 166 | </SCRIPT> | 
|---|
| 167 | <SCRIPT LANGUAGE=JavaScript> | 
|---|
| 168 | function QSimpleAX::ValueChanged( Newvalue ) | 
|---|
| 169 | { | 
|---|
| 170 | Calendar.Day = Newvalue; | 
|---|
| 171 | } | 
|---|
| 172 | </SCRIPT> | 
|---|
| 173 | </pre><p>See also <a href="qaxserver-examples.html">The QAxServer Examples</a>. | 
|---|
| 174 |  | 
|---|
| 175 | <!-- eof --> | 
|---|
| 176 | <p><address><hr><div align=center> | 
|---|
| 177 | <table width=100% cellspacing=0 border=0><tr> | 
|---|
| 178 | <td>Copyright © 2007 | 
|---|
| 179 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a> | 
|---|
| 180 | <td align=right><div align=right>Qt 3.3.8</div> | 
|---|
| 181 | </table></div></address></body> | 
|---|
| 182 | </html> | 
|---|