Results 1 to 5 of 5

Thread: link from QTextBrowser to QWebView

  1. #1
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default link from QTextBrowser to QWebView

    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:

    Qt Code:
    1. QWebView *webview;
    2. QTextBrowser *browser;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. connect(browser, SIGNAL(sourceChanged(QUrl &)), this, SLOT(showLink(QUrl &)));
    To copy to clipboard, switch view to plain text mode 

    and then:

    Qt Code:
    1. showLink(const QUrl &link)
    2. {
    3. webview->load(QUrl(link));
    4. webview->show();
    5. }
    To copy to clipboard, switch view to plain text mode 

    anyway it doesn't work.

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

    thanks for any help.
    Last edited by lamera; 9th October 2008 at 15:24.

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: link from QTextBrowser to QWebView

    Just off the top of my head, maybe try putting "const" in the signal/slot connection parameters?

  3. #3
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: link from QTextBrowser to QWebView

    hi!
    tried that too, but it doesn't help, anyway thanks for the reply

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: link from QTextBrowser to QWebView

    Quote Originally Posted by lamera View Post
    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().
    J-P Nurmi

  5. #5
    Join Date
    Jul 2008
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: link from QTextBrowser to QWebView

    it actually doesn't need a signal, I just put the
    Qt Code:
    1. webview->load(url);
    To copy to clipboard, switch view to plain text mode 
    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:

    Qt Code:
    1. virtual void setSource(const QUrl &link) {
    2. if ((link.toString()).endsWith(".pdf")){
    3. qDebug() << "Loading PDF viewer on " << link.toString();
    4. }
    5. else {
    6. webview->load(link);
    7. webview->show();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    should I make use of the QProcess class?

Similar Threads

  1. QWebView - retrieving information?
    By lamera in forum Qt Programming
    Replies: 1
    Last Post: 25th September 2008, 17:53
  2. How to detect link added in QTextBrowser?
    By live_07 in forum Qt Programming
    Replies: 1
    Last Post: 8th July 2008, 05:40
  3. QTextBrowser - click on link - closes window
    By bruccutler in forum Newbie
    Replies: 2
    Last Post: 19th June 2007, 20:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.