Get confirmation that a key has reached JS
-
OK, fine. What if there is nothing ... on the very same console all qDebug() perfectly appear?
wrote on 12 Dec 2016, 16:44 last edited by@McLion No, they go to JS console. You can see it in Inspector, or handle QWebPage::javaScriptConsoleMessage signal
-
@McLion No, they go to JS console. You can see it in Inspector, or handle QWebPage::javaScriptConsoleMessage signal
wrote on 12 Dec 2016, 16:50 last edited byAhhh ... OK ... Thanks a lot.
Never saw the 'Inspector' and will try to read it up ... is it also part of webKit in Qt?
I know the inspector on desktop browser but it won't help because it unfortunately does not show the issue there.
I'll try (tomorrow) to connect the signal to a slot and use qDebug() in there. -
Ahhh ... OK ... Thanks a lot.
Never saw the 'Inspector' and will try to read it up ... is it also part of webKit in Qt?
I know the inspector on desktop browser but it won't help because it unfortunately does not show the issue there.
I'll try (tomorrow) to connect the signal to a slot and use qDebug() in there.wrote on 13 Dec 2016, 14:29 last edited by@McLion
Activated the inspector with the following line:
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
Basically works. However, as soon as I have the inspector turned on my webView's do behave very strange, like they do not get all inputs anymore, and I can not debug the situation.Looks like I need to implement
QWebPage::javaScriptConsoleMessage
and send the messages back to C++ and debug from there.
According docs this is not a signal so I can not simply connect to it. -
@McLion
Activated the inspector with the following line:
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
Basically works. However, as soon as I have the inspector turned on my webView's do behave very strange, like they do not get all inputs anymore, and I can not debug the situation.Looks like I need to implement
QWebPage::javaScriptConsoleMessage
and send the messages back to C++ and debug from there.
According docs this is not a signal so I can not simply connect to it.wrote on 13 Dec 2016, 14:31 last edited by@McLion Right, I've mixed it up with new consoleMessageReceived() signal that is present in revived QtWebKit only (since TP3)
-
@McLion Right, I've mixed it up with new consoleMessageReceived() signal that is present in revived QtWebKit only (since TP3)
wrote on 13 Dec 2016, 15:42 last edited by@Konstantin-Tokarev
Need some help ...
I have the following:
in h:#include <QWebPage> class DBGWebPage : public QWebPage { Q_OBJECT public: explicit DBGWebPage(QObject *parent = 0); protected: void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID ); };
in cpp:
void DBGWebPage::javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID ) { qDebug() << message << lineNumber << sourceID; }
and my webGUI's are derived from qWebView:
QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget());
How do I make it use the reimplementation of javaScriptConsoleMessage()?
-
@Konstantin-Tokarev
Need some help ...
I have the following:
in h:#include <QWebPage> class DBGWebPage : public QWebPage { Q_OBJECT public: explicit DBGWebPage(QObject *parent = 0); protected: void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID ); };
in cpp:
void DBGWebPage::javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID ) { qDebug() << message << lineNumber << sourceID; }
and my webGUI's are derived from qWebView:
QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget());
How do I make it use the reimplementation of javaScriptConsoleMessage()?
wrote on 13 Dec 2016, 15:44 last edited by@McLion QWebView::setPage
-
@McLion QWebView::setPage
wrote on 13 Dec 2016, 16:24 last edited by@Konstantin-Tokarev
Thanks .. seems to be too late for today ... I don't get it to build ... dam... -
@McLion QWebView::setPage
wrote on 13 Dec 2016, 16:53 last edited by@Konstantin-Tokarev
There's something I don't get ... probably soemthing with these C++ classes I'm always stumbling over:#include <QWebPage> class DBGWebPage : public QWebPage { Q_OBJECT public: explicit DBGWebPage(QObject *parent = 0); QWebPage *DebugWebPage; protected: void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID ); };
DBGWebPage::DBGWebPage(QObject *parent) : QWebPage(parent) { //QWebPage* DebugWebPage = new QWebPage; DebugWebPage = new QWebPage(this); }
QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID) { // check if already existing if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; } // check for max GUI count here if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; } // create new webGUI and add it to the list QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget()); webGUIMap.insert(iID, webGUI); // make some basic settings to the new GUI webGUI->setPage(DBGWebPage::DebugWebPage); webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID)); ......
Fehler:object missing in reference to 'DBGWebPage::DebugWebPage'
-
@Konstantin-Tokarev
There's something I don't get ... probably soemthing with these C++ classes I'm always stumbling over:#include <QWebPage> class DBGWebPage : public QWebPage { Q_OBJECT public: explicit DBGWebPage(QObject *parent = 0); QWebPage *DebugWebPage; protected: void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID ); };
DBGWebPage::DBGWebPage(QObject *parent) : QWebPage(parent) { //QWebPage* DebugWebPage = new QWebPage; DebugWebPage = new QWebPage(this); }
QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID) { // check if already existing if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; } // check for max GUI count here if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; } // create new webGUI and add it to the list QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget()); webGUIMap.insert(iID, webGUI); // make some basic settings to the new GUI webGUI->setPage(DBGWebPage::DebugWebPage); webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID)); ......
Fehler:object missing in reference to 'DBGWebPage::DebugWebPage'
wrote on 13 Dec 2016, 16:54 last edited byThis post is deleted! -
@Konstantin-Tokarev
There's something I don't get ... probably soemthing with these C++ classes I'm always stumbling over:#include <QWebPage> class DBGWebPage : public QWebPage { Q_OBJECT public: explicit DBGWebPage(QObject *parent = 0); QWebPage *DebugWebPage; protected: void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID ); };
DBGWebPage::DBGWebPage(QObject *parent) : QWebPage(parent) { //QWebPage* DebugWebPage = new QWebPage; DebugWebPage = new QWebPage(this); }
QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID) { // check if already existing if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; } // check for max GUI count here if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; } // create new webGUI and add it to the list QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget()); webGUIMap.insert(iID, webGUI); // make some basic settings to the new GUI webGUI->setPage(DBGWebPage::DebugWebPage); webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID)); ......
Fehler:object missing in reference to 'DBGWebPage::DebugWebPage'
Hi
webGUI->setPage(DBGWebPage::DebugWebPage);
I would expect be something like
DBGWebPage *page=new DBGWebPage();
webGUI->setPage(page->DebugWebPage);The other syntax seems odd ?
-
@Konstantin-Tokarev
There's something I don't get ... probably soemthing with these C++ classes I'm always stumbling over:#include <QWebPage> class DBGWebPage : public QWebPage { Q_OBJECT public: explicit DBGWebPage(QObject *parent = 0); QWebPage *DebugWebPage; protected: void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID ); };
DBGWebPage::DBGWebPage(QObject *parent) : QWebPage(parent) { //QWebPage* DebugWebPage = new QWebPage; DebugWebPage = new QWebPage(this); }
QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID) { // check if already existing if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; } // check for max GUI count here if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; } // create new webGUI and add it to the list QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget()); webGUIMap.insert(iID, webGUI); // make some basic settings to the new GUI webGUI->setPage(DBGWebPage::DebugWebPage); webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID)); ......
Fehler:object missing in reference to 'DBGWebPage::DebugWebPage'
wrote on 13 Dec 2016, 17:05 last edited by@McLion You derive DBGWebPage from QWebPage and add QWebPage* field to it, then try to use that QWebPage* field (which is vanilla QWebPage, not DBGWebPage) as it was static filed of DBGWebPage.
-
Hi
webGUI->setPage(DBGWebPage::DebugWebPage);
I would expect be something like
DBGWebPage *page=new DBGWebPage();
webGUI->setPage(page->DebugWebPage);The other syntax seems odd ?
-
@mrjj
Thanks.
In fact, the other syntax seemed wrong.
You code builds without error, however, crashes with SIGSEGV.wrote on 13 Dec 2016, 17:21 last edited by@McLion Because it should be
DBGWebPage *page=new DBGWebPage();
webGUI->setPage(page); -
wrote on 13 Dec 2016, 17:24 last edited by
I somehow understand all you're saying, but I so far am not able to modify my code to not crash.
Currently ended up with (modified to it while Konstantin was writing it too):DBGWebPage *page=new DBGWebPage(); webGUI->setPage(page);
and an empty constructor.
Still crashing .... I'm stumped. -
wrote on 13 Dec 2016, 17:37 last edited by
remove DebugWebPage and all code messing with it
-
wrote on 13 Dec 2016, 17:41 last edited by
Found something.
It actually works if comment 2 signal connects for the page, but I need these two.- networkAccessManager for SSL errors
- and the JS bridge
If the page has been set, do I need to connect these in a different way or do these now go to the wrong object?
QWebView * QTGUI_MainWindow::CreateNewWebGUI(int iID) { // check if already existing if(webGUIMap.value(iID) != 0) { qDebug("GUI %d existing", iID); return false; } // check for max GUI count here if(iID > GUI_COUNT_MAX) { qDebug("GUI %d failed - Max GUI ID is %d", iID, GUI_COUNT_MAX); return false; } // create new webGUI and add it to the list QWebView *webGUI = new QWebView(QTGUI_MainWindow::centralWidget()); webGUIMap.insert(iID, webGUI); // make some basic settings to the new GUI DBGWebPage *page=new DBGWebPage(); webGUI->setPage(page); webGUI->setObjectName(QString::fromUtf8("webGUI%1").arg(iID)); //qDebug() << "New webGUI:" << webGUI; //qDebug() << "Map:" << iID << webGUIMap.value(iID); webGUI->setStyleSheet(QString::fromUtf8("background-color: rgba(0, 0, 0, 0);")); webGUI->setUrl(QUrl("about:blank")); webGUI->setRenderHints(QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing); webGUI->page()->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); webGUI->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); webGUI->setGeometry(0, 0, SCREEN_SIZE_X, SCREEN_SIZE_Y); webGUI->setFocusPolicy(Qt::StrongFocus); webGUI->setMouseTracking(true); webGUI->setAcceptDrops(true); webGUIeventFilter *webGUIEvFil = new webGUIeventFilter; webGUI->installEventFilter(webGUIEvFil); webGUI->hide(); // connect load progress and finished signals connect(webGUI, SIGNAL(loadProgress(int)), ui->webGUIChangeProgressBar, SLOT(setValue(int))); connect(webGUI, SIGNAL(loadFinished(bool)), this, SLOT(webGUI_loadFinished(bool))); // prepare adding objects to JavaScript (bridge from JS to native code) // connect(webGUI->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject())); // setup SSL error handling // connect(webGUI->page()->networkAccessManager(), SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError> & )), // this, SLOT(HandleGUIsslErrors(QNetworkReply*, const QList<QSslError> & ))); return webGUI; }
-
remove DebugWebPage and all code messing with it
wrote on 13 Dec 2016, 17:44 last edited by@Konstantin-Tokarev
Did so - all removed. -
wrote on 15 Dec 2016, 16:55 last edited by McLion
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? -
wrote on 16 Dec 2016, 14:22 last edited by McLion
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. -
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.wrote on 17 Dec 2016, 06:45 last edited by@McLion Throw it in
gdb
or your debugger of choice and give us a backtrace and we can probably tell ya what the issue is.
16/33