PDA

View Full Version : Getting title of website



Agent021
13th May 2013, 13:18
Hello.
I'm writing my own web browser using WebKit built-in qt. I've created class PageX which contains QWebView object. I want to get the title of every visited website (content of <title> tags) and save it to some variable (QString, I guess). I've tried to use function title() from QWebView, but it holds an empty string by default and doesn't change its content when I open every next website. Please explain to me how can I deal with it.
I'm using Qt 4.8.4 with QtCreator 2.6.1.
Thanks in advance.

PS Please reply in polish if you, dear helper, speak polish.

anda_skoa
14th May 2013, 08:27
Hmm, I think that should work.

Have you tried reading title() in a slot connected to the titleChanged() signal?

Cheers,
_

Agent021
16th May 2013, 20:43
No, but to test, I've set displaying title() in LineEdit and I've run the browser. Nothing happened. The function still held an empty string. However, I've connected all this functions by signals and slots:

pagex.h:

signals:
void title(QString);

private slots:
void titleChanged(QString t);

pagex.cpp:

connect(ui->web, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged(QString)));
//...
void pagex::titleChanged(QString t){
emit title(t);
}

And now it works, I can display the title that I've searched for. Thanks for your help.

anda_skoa
17th May 2013, 08:50
If you don't need the title in pagex you can do a "signal forwarding" connect


connect(ui->web, SIGNAL(titleChanged(QString)), this, SIGNAL(title(QString)));


Cheers,
_

Agent021
18th May 2013, 18:30
O, thank you - I didn't know this possibility of connecting two signals. I actually need the title in other class so your advice helped me to save a lot of time.