Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 53

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- webbrowser.qdoc -->
<head>
  <title>Qt 4.6: Web Browser Example (ActiveQt)</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">Web Browser Example (ActiveQt)<br /><span class="subtitle"></span>
</h1>
<p>Files:</p>
<ul>
<li><a href="activeqt-webbrowser-mainwindow-ui.html">activeqt/webbrowser/mainwindow.ui</a></li>
<li><a href="activeqt-webbrowser-mainwindow-windowsmobile-ui.html">activeqt/webbrowser/mainwindow_windowsmobile.ui</a></li>
<li><a href="activeqt-webbrowser-webaxwidget-h.html">activeqt/webbrowser/webaxwidget.h</a></li>
<li><a href="activeqt-webbrowser-main-cpp.html">activeqt/webbrowser/main.cpp</a></li>
<li><a href="activeqt-webbrowser-webbrowser-pro.html">activeqt/webbrowser/webbrowser.pro</a></li>
</ul>
<p>The Web Browser example uses the Microsoft Web Browser ActiveX control to implement a fully functional Web Browser application. The user interface has been developed using the Qt Designer integration of the <a href="qaxwidget.html">QAxWidget</a> class.</p>
<p>The code demonstrates how the Qt application can communicate with the embedded ActiveX controls using signals, slots and the dynamicCall() function.</p>
<pre> class MainWindow : public QMainWindow, public Ui::MainWindow
 {
     Q_OBJECT
 public:
     MainWindow();

 public slots:
     void on_WebBrowser_TitleChange(const QString &amp;title);
     void on_WebBrowser_ProgressChange(int a, int b);
     void on_WebBrowser_CommandStateChange(int cmd, bool on);
     void on_WebBrowser_BeforeNavigate();
     void on_WebBrowser_NavigateComplete(QString);

     void on_actionGo_triggered();
     void on_actionNewWindow_triggered();
     void on_actionAbout_triggered();
     void on_actionAboutQt_triggered();
     void on_actionFileClose_triggered();

 private:
     QProgressBar *pb;
 };</pre>
<p>The <tt>MainWindow</tt> class declares a <tt>QMainWindow</tt> based user interface, using the <tt>Ui::MainWindow</tt> class generated by Qt Designer. A number of slots are implemented to handle events from the various user interface elements, including the <tt>WebBrowser</tt> object, which is a <a href="qaxwidget.html">QAxWidget</a> hosting the Microsoft Web Browser control.</p>
<pre> MainWindow::MainWindow()
 {
     setupUi(this);

     connect(addressEdit, SIGNAL(returnPressed()), actionGo, SLOT(trigger()));
     connect(actionBack, SIGNAL(triggered()), WebBrowser, SLOT(GoBack()));
     connect(actionForward, SIGNAL(triggered()), WebBrowser, SLOT(GoForward()));
     connect(actionStop, SIGNAL(triggered()), WebBrowser, SLOT(Stop()));
     connect(actionRefresh, SIGNAL(triggered()), WebBrowser, SLOT(Refresh()));
     connect(actionHome, SIGNAL(triggered()), WebBrowser, SLOT(GoHome()));
     connect(actionSearch, SIGNAL(triggered()), WebBrowser, SLOT(GoSearch()));

     pb = new QProgressBar(statusBar());
     pb-&gt;setTextVisible(false);
     pb-&gt;hide();
     statusBar()-&gt;addPermanentWidget(pb);

     WebBrowser-&gt;dynamicCall(&quot;GoHome()&quot;);
 }</pre>
<p>The constructor initializes the user interface, installs a progress bar on the status bar, and uses <a href="qaxbase.html#dynamicCall">QAxBase::dynamicCall</a>() to invoke the <tt>GoHome()</tt> method of Internet Explorer to navigate to the user's home page.</p>
<pre> void MainWindow::on_WebBrowser_TitleChange(const QString &amp;title)
 {
     setWindowTitle(&quot;Qt WebBrowser - &quot; + title);
 }

 void MainWindow::on_WebBrowser_ProgressChange(int a, int b)
 {
     if (a &lt;= 0 || b &lt;= 0) {
         pb-&gt;hide();
         return;
     }
     pb-&gt;show();
     pb-&gt;setRange(0, b);
     pb-&gt;setValue(a);
 }

 void MainWindow::on_WebBrowser_CommandStateChange(int cmd, bool on)
 {
     switch (cmd) {
     case 1:
         actionForward-&gt;setEnabled(on);
         break;
     case 2:
         actionBack-&gt;setEnabled(on);
         break;
     }
 }

 void MainWindow::on_WebBrowser_BeforeNavigate()
 {
     actionStop-&gt;setEnabled(true);
 }

 void MainWindow::on_WebBrowser_NavigateComplete(QString)
 {
     actionStop-&gt;setEnabled(false);
 }</pre>
<p>Different slots handle the signals emitted by the WebBrowser object.</p>
<p>Connections that don't require any coding, i.e&#x2e; connecting the <tt>back</tt> action to the <tt>GoBack()</tt> slot, have already been made in Qt Designer.</p>
<pre> void MainWindow::on_actionGo_triggered()
 {
     WebBrowser-&gt;dynamicCall(&quot;Navigate(const QString&amp;)&quot;, addressEdit-&gt;text());
 }

 void MainWindow::on_actionNewWindow_triggered()
 {
     MainWindow *window = new MainWindow;
     window-&gt;show();
     if (addressEdit-&gt;text().isEmpty())
         return;
     window-&gt;addressEdit-&gt;setText(addressEdit-&gt;text());
     window-&gt;actionStop-&gt;setEnabled(true);
     window-&gt;on_actionGo_triggered();
 }

 void MainWindow::on_actionAbout_triggered()
 {
     QMessageBox::about(this, tr(&quot;About WebBrowser&quot;),
                 tr(&quot;This Example has been created using the ActiveQt integration into Qt Designer.\n&quot;
                    &quot;It demonstrates the use of QAxWidget to embed the Internet Explorer ActiveX\n&quot;
                    &quot;control into a Qt application.&quot;));
 }

 void MainWindow::on_actionAboutQt_triggered()
 {
     QMessageBox::aboutQt(this, tr(&quot;About Qt&quot;));
 }

 void MainWindow::on_actionFileClose_triggered()
 {
     close();
 }

 #include &quot;main.moc&quot;

 int main(int argc, char ** argv)
 {
     QApplication a(argc, argv);
     MainWindow w;
 #if defined(Q_OS_WINCE)
     w.showMaximized();
 #else
     w.show();
 #endif
     return a.exec();
 }</pre>
<p>The rest of the implementation is not related to <a href="activeqt.html#activeqt">ActiveQt</a> - the actions are handled by different slots, and the entry point function starts the application using standard Qt APIs.</p>
<p>To build the example you must first build the <a href="qaxcontainer.html">QAxContainer</a> library. Then run your make tool in <tt>examples/activeqt/webbrowser</tt> and run the resulting <tt>webbrowser.exe</tt>.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>