Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# A Web Browser

This example utilizes 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 QAxWidget class.

The code demonstrates how the Qt application can communicate with the embedded ActiveX controls using signals, slots and the dynamicCall() function. Most signal and slot connections have already been set up within Qt Designer.

        void MainWindow::init()
        {
            pb = new QProgressBar( statusBar() );
            pb->setPercentageVisible( FALSE );
            pb->hide();
            statusBar()->addWidget( pb, 0, TRUE );

            connect( WebBrowser, SIGNAL(ProgressChange(int,int)), this, SLOT(setProgress(int,int)) );
            connect( WebBrowser, SIGNAL(StatusTextChange(const QString&)), statusBar(), SLOT(message(const QString&)) );

            WebBrowser->dynamicCall( "GoHome()" );
        }

The init() function is implemented to create a progress bar as the child of the status bar, and to connect Internet Explorer's `ProgressChange()` and `StatusTextChange()` signals to the respective displays.

Finally the `GoHome()` function of Internet Explorer is invoked using the QAxBase::dynamicCall() dynamicCall() API.

        void MainWindow::go()
        {
            actionStop->setEnabled( TRUE );
            WebBrowser->dynamicCall( "Navigate(const QString&)", addressEdit->text() );
        }

The go() function calls the `NavigateTo()` function of Internet Explorer, passing the text of the address bar as the argument.

        void MainWindow::setTitle( const QString &title )
        {
            setCaption( "Qt WebBrowser - " + title );
        }

The setTitle() slot is connected to the TitleChange() signal of Internet Explorer, and updates the caption of the window using the provided title string.

        void MainWindow::setProgress( int a, int b )
        {
            if ( a <= 0 || b <= 0 ) {
                pb->hide();
                return;
            }
            pb->show();
            pb->setTotalSteps( b );
            pb->setProgress( a );
        }

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

        void MainWindow::navigateBegin()
        {
            actionStop->setEnabled( TRUE );
        }

        void MainWindow::navigateComplete()
        {
            actionStop->setEnabled( FALSE );
        }

The setProgress(), setCommandState(), navigateBegin() and navigateComplete() slots are connected to the respective signals of Internet Explorer and update the user interface.

The rest of the implementation is not related to ActiveQt and omitted for brevity.

To build the example you must first build the QAxContainer library. Then run your make tool in `examples/webbrowser` and run the resulting `webbrowser.exe`.

See also The QAxContainer Examples.