source: trunk/doc/html/qaxcontainer-example-webbrowser.html

Last change on this file was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 5.3 KB
Line 
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/webbrowser/webbrowser.doc:1 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>A Web Browser</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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 Web Browser</h1>
33
34
35
36This example utilizes the Microsoft Web Browser ActiveX control
37to implement a fully functional Web Browser application. The
38user interface has been developed using the Qt Designer
39integration of the <a href="qaxwidget.html">QAxWidget</a> class.
40<p> The code demonstrates how the Qt application can communicate
41with the embedded ActiveX controls using signals, slots and the
42dynamicCall() function. Most signal and slot connections have
43already been set up within Qt Designer.
44<p>
45
46<pre> void MainWindow::init()
47 {
48 pb = new <a href="qprogressbar.html">QProgressBar</a>( statusBar() );
49 <a name="x2513"></a> pb-&gt;<a href="qprogressbar.html#setPercentageVisible">setPercentageVisible</a>( FALSE );
50 <a name="x2516"></a> pb-&gt;<a href="qwidget.html#hide">hide</a>();
51 statusBar()-&gt;addWidget( pb, 0, TRUE );
52
53 connect( WebBrowser, SIGNAL(ProgressChange(int,int)), this, SLOT(setProgress(int,int)) );
54 connect( WebBrowser, SIGNAL(StatusTextChange(const <a href="qstring.html">QString</a>&amp;)), statusBar(), SLOT(message(const <a href="qstring.html">QString</a>&amp;)) );
55
56 WebBrowser-&gt;dynamicCall( "GoHome()" );
57 }
58</pre>The init() function is implemented to create a progress bar as
59the child of the status bar, and to connect Internet Explorer's
60<tt>ProgressChange()</tt> and <tt>StatusTextChange()</tt> signals to the
61respective displays.
62<p> Finally the <tt>GoHome()</tt> function of Internet Explorer is invoked
63using the <a href="qaxbase.html#dynamicCall">QAxBase::dynamicCall</a>() dynamicCall() API.
64<p> <pre> void MainWindow::go()
65 {
66 actionStop-&gt;setEnabled( TRUE );
67 WebBrowser-&gt;dynamicCall( "Navigate(const <a href="qstring.html">QString</a>&amp;)", addressEdit-&gt;text() );
68 }
69</pre>The go() function calls the <tt>NavigateTo()</tt> function of Internet
70Explorer, passing the text of the address bar as the argument.
71<p> <pre> void MainWindow::setTitle( const <a href="qstring.html">QString</a> &amp;title )
72 {
73 setCaption( "Qt WebBrowser - " + title );
74 }
75</pre>The setTitle() slot is connected to the TitleChange() signal
76of Internet Explorer, and updates the caption of the window
77using the provided title string.
78<p> <pre> void MainWindow::setProgress( int a, int b )
79 {
80 if ( a &lt;= 0 || b &lt;= 0 ) {
81 pb-&gt;<a href="qwidget.html#hide">hide</a>();
82 return;
83 }
84 pb-&gt;<a href="qwidget.html#show">show</a>();
85 <a name="x2515"></a> pb-&gt;<a href="qprogressbar.html#setTotalSteps">setTotalSteps</a>( b );
86 <a name="x2514"></a> pb-&gt;<a href="qprogressbar.html#setProgress">setProgress</a>( a );
87 }
88
89 void MainWindow::setCommandState( int cmd, bool on )
90 {
91 switch ( cmd ) {
92 case 1:
93 actionForward-&gt;setEnabled( on );
94 break;
95 case 2:
96 actionBack-&gt;setEnabled( on );
97 break;
98 }
99 }
100
101 void MainWindow::navigateBegin()
102 {
103 actionStop-&gt;setEnabled( TRUE );
104 }
105
106 void MainWindow::navigateComplete()
107 {
108 actionStop-&gt;setEnabled( FALSE );
109 }
110</pre>The setProgress(), setCommandState(), navigateBegin() and
111navigateComplete() slots are connected to the respective
112signals of Internet Explorer and update the user interface.
113<p> The rest of the implementation is not related to <a href="activeqt.html#ActiveQt">ActiveQt</a> and
114omitted for brevity.
115<p> To build the example you must first build the
116<a href="qaxcontainer.html">QAxContainer</a> library.
117Then run your make tool in <tt>examples/webbrowser</tt> and
118run the resulting <tt>webbrowser.exe</tt>.
119<p>See also <a href="qaxcontainer-examples.html">The QAxContainer Examples</a>.
120
121<!-- eof -->
122<p><address><hr><div align=center>
123<table width=100% cellspacing=0 border=0><tr>
124<td>Copyright &copy; 2007
125<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
126<td align=right><div align=right>Qt 3.3.8</div>
127</table></div></address></body>
128</html>
Note: See TracBrowser for help on using the repository browser.