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
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
You can use QObject::sender() but that breaks the oo design.
You have to cast sender() to QWebView. See qobject_cast.
it's working but sender is always MainWindow.
i have something like this :
Qt Code:
and slot: { . . . }To copy to clipboard, switch view to plain text mode
nwb is QWebView. That's problem with sender? slot in MainWindow class?
Is it possible to use a signal mapper?
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... yetSome advice?
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.
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)
I'm sorry, I'm an idiot.
A signal mapper will not work here since you can only use signals with no parameters.
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:
QWebPage *theWebPageWhoSentTheSignal = qobject_cast<QWebPage *>(sender()); If (theWebPageWhoSentTheSignal ) { ... }To copy to clipboard, switch view to plain text mode
it's exactly what i wrote earlierand returns MainWindow.
How for example chrome know which webview linkclicked signal was emitted? it is possiblei am seeking further
thank You anyway
![]()
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:
{ 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. If (theWebPageWhoSentTheSignal) { // the if(...) check if the page pointer is 0, if not, you can use it to do something. } }To copy to clipboard, switch view to plain text mode
maston (7th September 2010)
You have rightNow I'm stupid
Qt Code:
If (theWebPageWhoSentTheSignal) { }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:
if(theWebPageWhoSentTheSignal ) { QWebView *okobj = qobject_cast<QWebView *>(obj); okobj->load(url); }To copy to clipboard, switch view to plain text mode
Last edited by maston; 7th September 2010 at 20:36.
Bookmarks