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 TQt Designer integration of the TQAxWidget class.

The code demonstrates how the TQt 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 TQt Designer.

        void MainWindow::init()
        {
            pb = new TQProgressBar( statusBar() );
            pb->setPercentageVisible( false );
            pb->hide();
            statusBar()->addWidget( pb, 0, true );

            connect( WebBrowser, TQ_SIGNAL(ProgressChange(int,int)), this, TQ_SLOT(setProgress(int,int)) );
            connect( WebBrowser, TQ_SIGNAL(StatusTextChange(const TQString&)), statusBar(), TQ_SLOT(message(const TQString&)) );

            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 TQAxBase::dynamicCall() dynamicCall() API.

        void MainWindow::go()
        {
            actionStop->setEnabled( true );
            WebBrowser->dynamicCall( "Navigate(const TQString&)", 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 TQString &title )
        {
            setCaption( "TQt 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 ActiveTQt and omitted for brevity.

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

See also The TQAxContainer Examples.