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"><!--
|
---|
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 Web Browser</h1>
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 | This example utilizes the Microsoft Web Browser ActiveX control
|
---|
37 | to implement a fully functional Web Browser application. The
|
---|
38 | user interface has been developed using the Qt Designer
|
---|
39 | integration of the <a href="qaxwidget.html">QAxWidget</a> class.
|
---|
40 | <p> The code demonstrates how the Qt application can communicate
|
---|
41 | with the embedded ActiveX controls using signals, slots and the
|
---|
42 | dynamicCall() function. Most signal and slot connections have
|
---|
43 | already 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-><a href="qprogressbar.html#setPercentageVisible">setPercentageVisible</a>( FALSE );
|
---|
50 | <a name="x2516"></a> pb-><a href="qwidget.html#hide">hide</a>();
|
---|
51 | statusBar()->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>&)), statusBar(), SLOT(message(const <a href="qstring.html">QString</a>&)) );
|
---|
55 |
|
---|
56 | WebBrowser->dynamicCall( "GoHome()" );
|
---|
57 | }
|
---|
58 | </pre>The init() function is implemented to create a progress bar as
|
---|
59 | the child of the status bar, and to connect Internet Explorer's
|
---|
60 | <tt>ProgressChange()</tt> and <tt>StatusTextChange()</tt> signals to the
|
---|
61 | respective displays.
|
---|
62 | <p> Finally the <tt>GoHome()</tt> function of Internet Explorer is invoked
|
---|
63 | using the <a href="qaxbase.html#dynamicCall">QAxBase::dynamicCall</a>() dynamicCall() API.
|
---|
64 | <p> <pre> void MainWindow::go()
|
---|
65 | {
|
---|
66 | actionStop->setEnabled( TRUE );
|
---|
67 | WebBrowser->dynamicCall( "Navigate(const <a href="qstring.html">QString</a>&)", addressEdit->text() );
|
---|
68 | }
|
---|
69 | </pre>The go() function calls the <tt>NavigateTo()</tt> function of Internet
|
---|
70 | Explorer, passing the text of the address bar as the argument.
|
---|
71 | <p> <pre> void MainWindow::setTitle( const <a href="qstring.html">QString</a> &title )
|
---|
72 | {
|
---|
73 | setCaption( "Qt WebBrowser - " + title );
|
---|
74 | }
|
---|
75 | </pre>The setTitle() slot is connected to the TitleChange() signal
|
---|
76 | of Internet Explorer, and updates the caption of the window
|
---|
77 | using the provided title string.
|
---|
78 | <p> <pre> void MainWindow::setProgress( int a, int b )
|
---|
79 | {
|
---|
80 | if ( a <= 0 || b <= 0 ) {
|
---|
81 | pb-><a href="qwidget.html#hide">hide</a>();
|
---|
82 | return;
|
---|
83 | }
|
---|
84 | pb-><a href="qwidget.html#show">show</a>();
|
---|
85 | <a name="x2515"></a> pb-><a href="qprogressbar.html#setTotalSteps">setTotalSteps</a>( b );
|
---|
86 | <a name="x2514"></a> pb-><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->setEnabled( on );
|
---|
94 | break;
|
---|
95 | case 2:
|
---|
96 | actionBack->setEnabled( on );
|
---|
97 | break;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | void MainWindow::navigateBegin()
|
---|
102 | {
|
---|
103 | actionStop->setEnabled( TRUE );
|
---|
104 | }
|
---|
105 |
|
---|
106 | void MainWindow::navigateComplete()
|
---|
107 | {
|
---|
108 | actionStop->setEnabled( FALSE );
|
---|
109 | }
|
---|
110 | </pre>The setProgress(), setCommandState(), navigateBegin() and
|
---|
111 | navigateComplete() slots are connected to the respective
|
---|
112 | signals 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
|
---|
114 | omitted for brevity.
|
---|
115 | <p> To build the example you must first build the
|
---|
116 | <a href="qaxcontainer.html">QAxContainer</a> library.
|
---|
117 | Then run your make tool in <tt>examples/webbrowser</tt> and
|
---|
118 | run 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 © 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>
|
---|