This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[KHTML] Open URL when is clicked

Tags: None
(comma "," separated)
Terbaddo
Registered Member
Posts
3
Karma
0
OS

[KHTML] Open URL when is clicked

Fri Aug 13, 2010 10:34 am
Hello,
I'm developping Qt Application and I want incorporate KHTML within. So I created simple Qt app within KHTML. This is not KDE app :P

I have this:
widget.h
Code: Select all
#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <khtmlview.h>
#include <khtml_part.h>
#include <dom/dom_html.h>

class Widget : public QWidget
{
Q_OBJECT
public:
    explicit Widget(QWidget *parent = 0);

signals:

private:
    KHTMLPart *w;
};

#endif // WIDGET_H


widget.cpp
Code: Select all
#include "widget.h"
#include <QVBoxLayout>

Widget::Widget(QWidget *parent) :
    QWidget(parent)
{
    KUrl url = QString("http://www.kde.org");
    w = new KHTMLPart;
    w->openUrl(url);

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addWidget(w->widget());
    setLayout(layout);
}


main.cpp
Code: Select all
#include <QApplication>
#include "widget.h"


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Widget w;
    w.show();

    return a.exec();
}


It loads normally http://www.kde.org . But when I click in any URL, no page was loaded (http://kde.org always here).
What I must do for load clicked URLs?

Thanks.
pinotree
KDE Developer
Posts
222
Karma
7
OS

Re: [KHTML] Open URL when is clicked

Fri Aug 13, 2010 10:55 am
You get the browserExtension() of the KHTMLPart, and then connect to any of the signals of the BrowserExtension class. In your case, the openUrlRequest signal should do the job.


Pino Toscano
Terbaddo
Registered Member
Posts
3
Karma
0
OS

Re: [KHTML] Open URL when is clicked

Fri Aug 13, 2010 11:31 am
Ok, it works.

Thanks


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]