PDA

View Full Version : link from QTextBrowser to QWebView



lamera
9th October 2008, 14:39
hi!

I've got an application which shows a list of links in QTextBrowser, but if the user clicks one of them I want them to appear in a different - QWebView, not in QTextBrowser, I want the QTextBrowser to remain the same.

so I've done:



QWebView *webview;
QTextBrowser *browser;



connect(browser, SIGNAL(sourceChanged(QUrl &)), this, SLOT(showLink(QUrl &)));

and then:



showLink(const QUrl &link)
{
webview->load(QUrl(link));
webview->show();
}

anyway it doesn't work.

So I subclassed QTextBrowser and modified setSource() to do nothing. Still doesn't work...

thanks for any help.

JimDaniel
9th October 2008, 17:29
Just off the top of my head, maybe try putting "const" in the signal/slot connection parameters?

lamera
9th October 2008, 18:27
hi!
tried that too, but it doesn't help, anyway thanks for the reply :)

jpn
12th October 2008, 11:14
I've got an application which shows a list of links in QTextBrowser, but if the user clicks one of them I want...
In that case QTextBrowser::sourceChanged() is a wrong signal. You're interested in QTextBrowser::anchorClicked().

lamera
12th October 2008, 15:46
it actually doesn't need a signal, I just put the

webview->load(url);
command into the QTextBrowser::setSource(QUrl & url) function and it works!

what I'm trying to figure out now is how to handle it if the link is a PDF...
I've seen a few threads on other forums, but still the solutions don't seem to work.

If the link is to a pdf I would like the program to open a windows-like window saying
Opening name.PDF and then he chooses the default program (e.g.Adobe Reader) or gives the ability to choose sth else.

So I've tries sth like:



virtual void setSource(const QUrl &link) {
if ((link.toString()).endsWith(".pdf")){
qDebug() << "Loading PDF viewer on " << link.toString();
}
else {
webview->load(link);
webview->show();
}
}

should I make use of the QProcess class?