File: activeqt-simple.html

package info (click to toggle)
qt4-x11 4%3A4.8.2%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 701,696 kB
  • sloc: cpp: 2,686,179; ansic: 375,485; python: 25,859; sh: 19,349; xml: 17,091; perl: 14,765; yacc: 5,383; asm: 5,038; makefile: 1,259; lex: 555; ruby: 526; objc: 347; cs: 112; pascal: 112; php: 54; sed: 34
file content (180 lines) | stat: -rw-r--r-- 12,184 bytes parent folder | download
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- simple.qdoc -->
  <title>Qt 4.8: Simple Example (ActiveQt)</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li><a href="all-examples.html">Examples</a></li>
<li>Simple Example (ActiveQt)</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<h1 class="title">Simple Example (ActiveQt)</h1>
<span class="subtitle"></span>
<!-- $$$activeqt/simple-description -->
<div class="descr"> <a name="details"></a>
<p>Files:</p>
<ul>
<li><a href="activeqt-simple-main-cpp.html">activeqt/simple/main.cpp</a></li>
<li><a href="activeqt-simple-simple-pro.html">activeqt/simple/simple.pro</a></li>
</ul>
<p>The Simple example demonstrates the use of <a href="qaxbindable.html#requestPropertyChange">QAxBindable::requestPropertyChange</a>() and <a href="qaxbindable.html#propertyChanged">QAxBindable::propertyChanged</a>(), and the use of the default <a href="qaxfactory.html">QAxFactory</a> through the <tt>QAXFACTORY_DEFAULT()</tt> macro.</p>
<p>The ActiveX control in this example is a laid out <a href="qwidget.html">QWidget</a> with a <a href="qslider.html">QSlider</a>, a <a href="qlcdnumber.html">QLCDNumber</a> and a <a href="qlineedit.html">QLineEdit</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>
<p>The Qt implementation of the ActiveX for this example is</p>
<pre class="cpp"> <span class="keyword">class</span> <span class="type">QSimpleAX</span> : <span class="keyword">public</span> <span class="type"><a href="qwidget.html">QWidget</a></span><span class="operator">,</span> <span class="keyword">public</span> <span class="type"><a href="qaxbindable.html">QAxBindable</a></span>
 {
     Q_OBJECT
     Q_PROPERTY( <span class="type"><a href="qstring.html">QString</a></span> text READ text WRITE setText )
     Q_PROPERTY( <span class="type">int</span> value READ value WRITE setValue )
 <span class="keyword">public</span>:
     <span class="type">QSimpleAX</span>(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent <span class="operator">=</span> <span class="number">0</span>)
     : <span class="type"><a href="qwidget.html">QWidget</a></span>(parent)
     {
         <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>vbox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>( <span class="keyword">this</span> );

         slider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>( <span class="type"><a href="qt.html">Qt</a></span><span class="operator">::</span>Horizontal<span class="operator">,</span> <span class="keyword">this</span> );
         LCD <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlcdnumber.html">QLCDNumber</a></span>( <span class="number">3</span><span class="operator">,</span> <span class="keyword">this</span> );
         edit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>( <span class="keyword">this</span> );

         connect( slider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(setValue(<span class="type">int</span>)) );
         connect( edit<span class="operator">,</span> SIGNAL(textChanged(<span class="type"><a href="qstring.html">QString</a></span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(setText(<span class="type"><a href="qstring.html">QString</a></span>)) );

         vbox<span class="operator">-</span><span class="operator">&gt;</span>addWidget( slider );
         vbox<span class="operator">-</span><span class="operator">&gt;</span>addWidget( LCD );
         vbox<span class="operator">-</span><span class="operator">&gt;</span>addWidget( edit );
     }

     <span class="type"><a href="qstring.html">QString</a></span> text() <span class="keyword">const</span>
     {
         <span class="keyword">return</span> edit<span class="operator">-</span><span class="operator">&gt;</span>text();
     }
     <span class="type">int</span> value() <span class="keyword">const</span>
     {
         <span class="keyword">return</span> slider<span class="operator">-</span><span class="operator">&gt;</span>value();
     }

 <span class="keyword">signals</span>:
     <span class="type">void</span> someSignal();
     <span class="type">void</span> valueChanged(<span class="type">int</span>);
     <span class="type">void</span> textChanged(<span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span><span class="operator">&amp;</span>);

 <span class="keyword">public</span> <span class="keyword">slots</span>:
     <span class="type">void</span> setText( <span class="keyword">const</span> <span class="type"><a href="qstring.html">QString</a></span> <span class="operator">&amp;</span>string )
     {
         <span class="keyword">if</span> ( <span class="operator">!</span>requestPropertyChange( <span class="string">&quot;text&quot;</span> ) )
             <span class="keyword">return</span>;

         edit<span class="operator">-</span><span class="operator">&gt;</span>blockSignals( <span class="keyword">true</span> );
         edit<span class="operator">-</span><span class="operator">&gt;</span>setText( string );
         edit<span class="operator">-</span><span class="operator">&gt;</span>blockSignals( <span class="keyword">false</span> );
         <span class="keyword">emit</span> someSignal();
         <span class="keyword">emit</span> textChanged( string );

         propertyChanged( <span class="string">&quot;text&quot;</span> );
     }
     <span class="type">void</span> about()
     {
         <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>information( <span class="keyword">this</span><span class="operator">,</span> <span class="string">&quot;About QSimpleAX&quot;</span><span class="operator">,</span> <span class="string">&quot;This is a Qt widget, and this slot has been\n&quot;</span>
                                                           <span class="string">&quot;called through ActiveX/OLE automation!&quot;</span> );
     }
     <span class="type">void</span> setValue( <span class="type">int</span> i )
     {
         <span class="keyword">if</span> ( <span class="operator">!</span>requestPropertyChange( <span class="string">&quot;value&quot;</span> ) )
             <span class="keyword">return</span>;
         slider<span class="operator">-</span><span class="operator">&gt;</span>blockSignals( <span class="keyword">true</span> );
         slider<span class="operator">-</span><span class="operator">&gt;</span>setValue( i );
         slider<span class="operator">-</span><span class="operator">&gt;</span>blockSignals( <span class="keyword">false</span> );
         LCD<span class="operator">-</span><span class="operator">&gt;</span>display( i );
         <span class="keyword">emit</span> valueChanged( i );

         propertyChanged( <span class="string">&quot;value&quot;</span> );
     }

 <span class="keyword">private</span>:
     <span class="type"><a href="qslider.html">QSlider</a></span> <span class="operator">*</span>slider;
     <span class="type"><a href="qlcdnumber.html">QLCDNumber</a></span> <span class="operator">*</span>LCD;
     <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>edit;
 };</pre>
<p>The control is exported using the default <a href="qaxfactory.html">QAxFactory</a></p>
<pre class="cpp"> <a href="qaxfactory.html#QAXFACTORY_DEFAULT">QAXFACTORY_DEFAULT</a>(<span class="type">QSimpleAX</span><span class="operator">,</span>
            <span class="string">&quot;{DF16845C-92CD-4AAB-A982-EB9840E74669}&quot;</span><span class="operator">,</span>
            <span class="string">&quot;{616F620B-91C5-4410-A74E-6B81C76FFFE0}&quot;</span><span class="operator">,</span>
            <span class="string">&quot;{E1816BBA-BF5D-4A31-9855-D6BA432055FF}&quot;</span><span class="operator">,</span>
            <span class="string">&quot;{EC08F8FC-2754-47AB-8EFE-56A54057F34E}&quot;</span><span class="operator">,</span>
            <span class="string">&quot;{A095BA0C-224F-4933-A458-2DD7F6B85D8F}&quot;</span>)</pre>
<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 <tt>examples/activeqt/simple</tt>.</p>
<p>The <a href="qaxserver-demo-simple.html">demonstration</a> requires your WebBrowser to support ActiveX controls, and scripting to be enabled.</p>
<p>The simple ActiveX control is embedded using the <tt>&lt;object&gt;</tt> tag.</p>
<pre class="cpp"> &lt;object ID=&quot;QSimpleAX&quot; CLASSID=&quot;CLSID:DF16845C-92CD-4AAB-A982-EB9840E74669&quot;
 CODEBASE=&quot;http://qt.nokia.com/demos/simpleax.cab&quot;&gt;
     &lt;PARAM NAME=&quot;text&quot; VALUE=&quot;A simple control&quot; /&gt;
     &lt;PARAM NAME=&quot;value&quot; VALUE=&quot;1&quot; /&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="activeqt.html#activeqt">ActiveQt</a>'s about() slot.</p>
<pre class="cpp"> &lt;FORM&gt;
     &lt;INPUT TYPE=&quot;BUTTON&quot; VALUE=&quot;About...&quot; onClick=&quot;QSimpleAX.about()&quot; /&gt;
 &lt;/FORM&gt;</pre>
<p>A second ActiveX control - the standard Calendar Control - is instantiated</p>
<pre class="cpp"> &lt;object ID=&quot;Calendar&quot; CLASSID=&quot;CLSID:8E27C92B-1264-101C-8A2F-040224009C02&quot;&gt;
 [Standard Calendar control not available!]
     &lt;PARAM NAME=&quot;day&quot; VALUE=&quot;1&quot; /&gt;
 &lt;/object&gt;</pre>
<p>Events from the ActiveX controls are handled using both Visual Basic Script and JavaScript.</p>
<pre class="cpp"> &lt;SCRIPT LANGUAGE=&quot;VBScript&quot;&gt;
 Sub Calendar_Click()
     MsgBox( &quot;Calendar Clicked!&quot; )
 End Sub

 Sub QSimpleAX_TextChanged( str )
     document.title = str
 End Sub
 &lt;/SCRIPT&gt;

 &lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;
 function QSimpleAX::ValueChanged( Newvalue )
 {
     Calendar.Day = Newvalue;
 }
 &lt;/SCRIPT&gt;</pre>
</div>
<!-- @@@activeqt/simple -->
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2012 Nokia Corporation and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>