Results 1 to 14 of 14

Thread: linkClicked signal

  1. #1
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default linkClicked signal

    Hi.

    How I can determine which webview widget emitted linkClicked signal?

    I have tabWidget with WebView *wv = new WebView() create after triggered action in new tabBar. And i don't know which widget emitted signal

    Please help
    Maston

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: linkClicked signal

    You can use QObject::sender() but that breaks the oo design.

  3. #3
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: linkClicked signal

    Quote Originally Posted by Lykurg View Post
    You can use QObject::sender() but that breaks the oo design.

    THank You... but how can I access to webview by the QObject.sender()?
    for example, i have to do webview->load(myclickedurl);

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: linkClicked signal

    You have to cast sender() to QWebView. See qobject_cast.

  5. #5
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: linkClicked signal

    it's working but sender is always MainWindow.

    i have something like this :

    Qt Code:
    1. connect( nwb->page() , SIGNAL( linkClicked(const QUrl &)), this, SLOT(link_click(const QUrl &)));
    2.  
    3. and slot:
    4. void MainWindow::link_click(const QUrl & ok)
    5. {
    6. . . .
    7. }
    To copy to clipboard, switch view to plain text mode 

    nwb is QWebView. That's problem with sender? slot in MainWindow class?

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: linkClicked signal

    Is it possible to use a signal mapper?

  7. #7
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: linkClicked signal

    signal mapper is declared in constructor right? my WebView is created by QTCreator ( ui_mainwindow.h ) .so i don't have access to constructor class.

    Or I don't know how to do it... yet Some advice?

  8. #8
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: linkClicked signal

    You define the mapper in your main window.
    Then you connect the linkClicked signal to the mapper map() slot.
    You set a mapping, like the pointer to the webview
    Then you connect the mapped signal to your custom slot having instant access to the calling webview.

  9. #9
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: linkClicked signal

    thank You...do You know how change argumets in mapped() signal? i have this:

    QObject::connect: Incompatible sender/receiver arguments
    QSignalMapper::mapped(QObject*) --> MainWindow::link_click(QUrl)

  10. #10
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: linkClicked signal

    I'm sorry, I'm an idiot.
    A signal mapper will not work here since you can only use signals with no parameters.

  11. #11
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: linkClicked signal

    Since I'm being stupid, here's another stupid idea ;-)

    For each webview, connect to a unique slot.
    This works if you have a small static amount of webviews. Not for a dynamic amount.


    But, using sender() should not return the main window.

    Qt Code:
    1. QWebPage *theWebPageWhoSentTheSignal = qobject_cast<QWebPage *>(sender());
    2.  
    3. If (theWebPageWhoSentTheSignal ) {
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 

  12. #12
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: linkClicked signal

    it's exactly what i wrote earlier and returns MainWindow.
    How for example chrome know which webview linkclicked signal was emitted? it is possible i am seeking further thank You anyway

  13. #13
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: linkClicked signal

    Quote Originally Posted by maston View Post
    it's exactly what i wrote earlier and returns MainWindow.
    That's not possible!

    A qobject_cast returns 0 if it can't cast the object. You can not cast a QWebPage to a QMainWindow.
    It would return 0 in your case.

    Qt Code:
    1. connect( nwb->page() , SIGNAL( linkClicked(const QUrl &)), this, SLOT(link_click(const QUrl &)));
    2.  
    3. void MainWindow::link_click(const QUrl & ok)
    4. {
    5. QWebPage *theWebPageWhoSentTheSignal = qobject_cast<QWebPage *>(sender()); //<-- this can NEVER return the main window. The only two possibilities are a pointer to a QWebPage or 0.
    6.  
    7. If (theWebPageWhoSentTheSignal) {
    8. // the if(...) check if the page pointer is 0, if not, you can use it to do something.
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

  14. The following user says thank you to tbscope for this useful post:

    maston (7th September 2010)

  15. #14
    Join Date
    May 2010
    Posts
    22
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: linkClicked signal

    You have right Now I'm stupid

    Qt Code:
    1. If (theWebPageWhoSentTheSignal) {
    2. qDebug() << QObject::objectName().toUtf8();
    3. }
    To copy to clipboard, switch view to plain text mode 

    this print MainWindow , but theWebPageWhoSentTheSignal must be QWebPage because qDebug is working... sorry

    edit2:

    Qt Code:
    1. if(theWebPageWhoSentTheSignal ) {
    2.  
    3. QObject *obj = theWebPageWhoSentTheSignal->parent();
    4. QWebView *okobj = qobject_cast<QWebView *>(obj);
    5. okobj->load(url);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by maston; 7th September 2010 at 20:36.

Similar Threads

  1. QWebView linkclicked and form submit
    By maddog_fr in forum Qt Programming
    Replies: 9
    Last Post: 8th August 2009, 20:03
  2. signal mapping on pushbutton signal clicked
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 07:54
  3. Signal-Signal Connections Between Threads
    By PhilippB in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2008, 18:27
  4. QWebPage::linkClicked() is only emitted once
    By Lykurg in forum Qt Programming
    Replies: 0
    Last Post: 20th November 2008, 12:56
  5. Replies: 1
    Last Post: 8th November 2007, 17:11

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.