summaryrefslogtreecommitdiffstats
path: root/doc/html/qaxserver-example-simple.html
blob: 5a8007c62ad80ed8adc8c143a5b57af827a64acb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/extensions/activeqt/examples/simple/simple.doc:45 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>A simple ActiveTQt control (executable)</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<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 ActiveTQt control (executable)</h1>

 

The ActiveX control in this example is a layouted <a href="ntqwidget.html">TQWidget</a>
with a <a href="ntqslider.html">TQSlider</a>, a <a href="ntqlcdnumber.html">TQLCDNumber</a> and a <a href="ntqlineedit.html">TQLineEdit</a>.
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.
<p> It demonstrates the use of <a href="qaxbindable.html#requestPropertyChange">TQAxBindable::requestPropertyChange</a>()
and <a href="qaxbindable.html#propertyChanged">TQAxBindable::propertyChanged</a>(), and the use of the default
<a href="qaxfactory.html">TQAxFactory</a> through the <a href="qaxfactory.html#TQAXFACTORY_DEFAULT">TQAXFACTORY_DEFAULT</a> macro.
<p> 

<p> The TQt implementation of the ActiveX for this example is
<pre>    class TQSimpleAX : public <a href="ntqwidget.html">TQWidget</a>, public TQAxBindable
    {
        <a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
        Q_PROPERTY( TQString text READ text WRITE setText )
        Q_PROPERTY( int value READ value WRITE setValue )
    public:
        TQSimpleAX( <a href="ntqwidget.html">TQWidget</a> *parent = 0, const char *name = 0 )
        : <a href="ntqwidget.html">TQWidget</a>( parent, name )
        {
            <a href="qvboxlayout.html">TQVBoxLayout</a> *vbox = new <a href="qvboxlayout.html">TQVBoxLayout</a>( this );

            slider = new <a href="ntqslider.html">TQSlider</a>( 0, 100, 1, 0, TQSlider::Horizontal, this );
            LCD = new <a href="ntqlcdnumber.html">TQLCDNumber</a>( 3, this );
            edit = new <a href="ntqlineedit.html">TQLineEdit</a>( this );

    <a name="x2528"></a>        connect( slider, SIGNAL( <a href="ntqslider.html#valueChanged">valueChanged</a>( int ) ), this, SLOT( setValue(int) ) );
    <a name="x2523"></a>        connect( edit, SIGNAL(<a href="ntqlineedit.html#textChanged">textChanged</a>(const <a href="ntqstring.html">TQString</a>&amp;)), this, SLOT(setText(const <a href="ntqstring.html">TQString</a>&amp;)) );

            vbox-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( slider );
            vbox-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( LCD );
            vbox-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>( edit );
        }

        <a href="ntqstring.html">TQString</a> text() const
        {
    <a name="x2522"></a>        return edit-&gt;<a href="ntqlineedit.html#text">text</a>();
        }
        int value() const
        {
    <a name="x2527"></a>        return slider-&gt;<a href="ntqslider.html#value">value</a>();
        }

    signals:
        void someSignal();
        void valueChanged(int);
        void textChanged(const <a href="ntqstring.html">TQString</a>&amp;);

    public slots:
        void setText( const <a href="ntqstring.html">TQString</a> &amp;string )
        {
            if ( !requestPropertyChange( "text" ) )
                return;

    <a name="x2525"></a>        edit-&gt;<a href="ntqobject.html#blockSignals">blockSignals</a>( TRUE );
    <a name="x2521"></a>        edit-&gt;<a href="ntqlineedit.html#setText">setText</a>( string );
            edit-&gt;<a href="ntqobject.html#blockSignals">blockSignals</a>( FALSE );
            emit someSignal();
            emit textChanged( string );

            propertyChanged( "text" );
        }
        void about()
        {
    <a name="x2524"></a>        TQMessageBox::<a href="ntqmessagebox.html#information">information</a>( 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-&gt;<a href="ntqobject.html#blockSignals">blockSignals</a>( TRUE );
    <a name="x2526"></a>        slider-&gt;<a href="ntqslider.html#setValue">setValue</a>( i );
            slider-&gt;<a href="ntqobject.html#blockSignals">blockSignals</a>( FALSE );
            LCD-&gt;<a href="ntqlcdnumber.html#display">display</a>( i );
            emit valueChanged( i );

            propertyChanged( "value" );
        }

    private:
        <a href="ntqslider.html">TQSlider</a> *slider;
        <a href="ntqlcdnumber.html">TQLCDNumber</a> *LCD;
        <a href="ntqlineedit.html">TQLineEdit</a> *edit;
    };
</pre>
<p> The control is exported using the default <a href="qaxfactory.html">TQAxFactory</a>
<pre>    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}")
</pre>
<p> To build the example you must first build the <a href="qaxserver.html">TQAxServer</a> library. Then run qmake and your make tool in 
<tt>examples/simple</tt>.
<p> <hr>
<p> The <a href="qaxserver-demo-simple.html">demonstration</a> requires your
WebBrowser to support ActiveX controls, and scripting to be enabled.
<p> The simple ActiveX control is embedded using the <tt>&lt;object&gt;</tt> tag.


<pre>    &lt;object ID="TQSimpleAX" CLASSID="CLSID:DF16845C-92CD-4AAB-A982-EB9840E74669"
    CODEBASE=http://www.trolltech.com/demos/simpleax.cab&gt;
        &lt;PARAM NAME="text" VALUE="A simple control"&gt;
        &lt;PARAM NAME="value" VALUE="1"&gt;
    [Object not available! Did you forget to build and register the server?]
    &lt;/object&gt;
</pre>
<p> A simple HTML button is connected to the <a href="activentqt.html#ActiveTQt">ActiveTQt</a>'s about() slot.
<pre>    &lt;FORM&gt;
        &lt;INPUT TYPE="BUTTON" VALUE="About..." onClick="TQSimpleAX.about()"&gt;
    &lt;/FORM&gt;
</pre>
<p> A second ActiveX control - the standard Calendar Control - is instantiated
<pre>    &lt;object ID="Calendar" CLASSID="CLSID:8E27C92B-1264-101C-8A2F-040224009C02"&gt;
    [Standard Calendar control not available!]
        &lt;PARAM NAME="day" VALUE="1"&gt;
    &lt;/object&gt;
</pre>
<p> Events from the ActiveX controls are handled using both Visual Basic Script
and JavaScript.
<pre>    &lt;SCRIPT LANGUAGE=VBScript&gt;
    Sub Calendar_Click()
        MsgBox( "Calendar Clicked!" )
    End Sub

    Sub TQSimpleAX_TextChanged( str )
        document.title = str
    End Sub
    &lt;/SCRIPT&gt;
    &lt;SCRIPT LANGUAGE=JavaScript&gt;
    function TQSimpleAX::ValueChanged( Newvalue )
    {
        Calendar.Day = Newvalue;
    }
    &lt;/SCRIPT&gt;
</pre><p>See also <a href="qaxserver-examples.html">The TQAxServer Examples</a>.

<!-- eof -->
<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>