Get confirmation that a key has reached JS
-
@Konstantin-Tokarev
Did so - all removed. -
I can not find what I'm doing wrong. The console debug works, as long as I have deactivated the JS bridge.
DBGWebPage *page=new DBGWebPage(); webGUI->setPage(page); // the following lines that use the new page seem to work webGUI->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); webGUI->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); // and the following line - that I need - let it crash upon boot: connect(webGUI->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()));
If I don't use setPage() to change the page that the webView generates by default, the JS bridge works perfectly.
What am I doing wrong to use the page of my own class with the debug added AND use the JS bridge? -
Anyone an idea what I'm doing wrong here?
The code does not crash while connecting. It seems to crashes when the first web page is loaded and the loadProgress or loadFinished signal is sent from the webView.
Edit/Add:
On second thought, it probably crashes when the javaScriptWindowObjectCleared() is called the first time. -
@ambershark
Unfortunately, I don't have any debugger running on this eLinux target. -
@McLion said in Get confirmation that a key has reached JS:
I can not find what I'm doing wrong. The console debug works, as long as I have deactivated the JS bridge.
DBGWebPage *page=new DBGWebPage(); webGUI->setPage(page); // the following lines that use the new page seem to work webGUI->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); webGUI->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); // and the following line - that I need - let it crash upon boot: connect(webGUI->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()));
If I don't use setPage() to change the page that the webView generates by default, the JS bridge works perfectly.
What am I doing wrong to use the page of my own class with the debug added AND use the JS bridge?@McLion Ok if that's the case you'll need to move to using qDebug() or some sort of cout/logfile debugging to figure out what's going on. If you need a logger for linux you're welcome to use mine at https://github.com/ambershark-mike/sharklog. It's not feature complete yet but is definitely more than usable. I use it in a number of projects.
Anyway, my guess with your crash is that
webGUI
orpage()
ormainFrame()
is invalid. One of those is causing the issue almost guaranteed. Assuming the crash is actually on that line. So for instance if you were using my logger you could check it with code like:// sorry for the casts to (int) on the pointers, I don't have hex address/pointer support in the logger yet. // it's a side project I don't have a ton of time for. :) LoggerStream() << "webGUI: " << (int)webGUI << SHARKLOG_END; LoggerStream() << "page: " << (int)webGUI->page() << SHARKLOG_END; LoggerStream() << "mainFrame: " << (int)webGUI->page()->mainFrame() << SHARKLOG_END;
The reason we do all those logs on a separate line is if any of them are bad they will crash. Put these in before your connect and check which object is bad. Probably a null (0), but potentially it has been deleted. If that is the case and it is a dangling pointer it is going to be harder to find without a debugger.
-
@ambershark
Oh, I'm using qDebug() a lot since I have a serial console connected to the embedded target that allows me to see everything from Linux and interact with it as well.The problem is that from within a JS in webKit there is no qDebug().
By subclassing webView and reimplementing javaScriptConsoleMessage() every console message in a JS (i.e.console.log("JS keyCode: " + event.keyCode);
) can be catched in C++ code and forwarded to the console by using qDebug().
Actually, this works ... as long as I don't connect the bridge and comment the following:// prepare adding objects to JavaScript (bridge from JS to native code) connect(webGUI->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()));
So, I assume that the object in the connect is the issue because page() is not automatically derived from the webView as it was before and has been changed to page() from my subclass DBGWebPage.
I just can't see what is wrong with the stuff I'm doing.
Thanks a lot anyway. -
@Konstantin-Tokarev
I'm not sure ... I think that should work if I share all Qt sources in my 'src' folder, does it?I am working and developing on Windows with Creator to have the output from the compiler and everything Creator offers. If it builds ok, I switch to my Linux Debian VM and build the ARM code from within the Linux console. The traget gets the code over the LAN directly from my Linux VM by NFS.
The application can not really be run on windows because there are some hardware components and other stuff that is available on the target only. I mean it runs, but you can't do anything with it on windows. -
Finally coming back to this ... and found the issue :-)
DBGWebPage *NewPage = new DBGWebPage(webGUI);
The new Page was not a child of the correct object.
I checked pointers as suggested.
The connect of the JS bridge showed no issues.
However, the first call from JS (signaljavaScriptWindowObjectCleared()
calling mypopulateJavaScriptWindowObject()
)
crashed onQWebFrame * webGUIframe = qobject_cast<QWebFrame *>(sender()); QWebView * webGUI = (QWebView*)(webGUIframe->parent())->parent();
obviously because it was pointing to 'nothing' instead of a QWebView.
Thank you guys for all the hints.