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
Printable View
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 :
Code:
and slot: { . . . }
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... yet :) Some 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.
Code:
QWebPage *theWebPageWhoSentTheSignal = qobject_cast<QWebPage *>(sender()); If (theWebPageWhoSentTheSignal ) { ... }
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 :)
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.
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. } }
You have right :) Now I'm stupid :D
this print MainWindow , but theWebPageWhoSentTheSignal must be QWebPage because qDebug is working... sorry :)
edit2:
Code:
if(theWebPageWhoSentTheSignal ) { QWebView *okobj = qobject_cast<QWebView *>(obj); okobj->load(url); }