I am getting this error:
main.cpp:31: error: no matching function for call to 'QWebFrame::addToJavaScriptWindowObject(QString, Eh*&)'
candidates are: void QWebFrame::addToJavaScriptWindowObject(const QString&, QObject*)
This is the source code:
#include <string>
#include <QtGui/QApplication>
#include <QWebFrame>
#include <QWebView>
#include <QGraphicsWebView>
#include <QWebPage>
#include "html5applicationviewer.h"
class Eh
{
int lol()
{
return 666;
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Html5ApplicationViewer viewer;
viewer.setOrientation(Html5ApplicationViewer::ScreenOrientationAuto);
viewer.showExpanded();
viewer.loadFile(QLatin1String("html/index.html"));
QWebPage *page = viewer.webView()->page();
QWebFrame *frame = page->mainFrame();
Eh *s = new Eh();
frame->addToJavaScriptWindowObject(QString("test"), s);
return app.exec();
}
I’ve tried giving a new instance of Eh and the Eh class itself. In both cases it fails. Also I can’t give the non-pointer of it since new returns a pointer.
My question is this: why is it Eh*& and not Eh*?
addToJavaScriptWindowObjecttakes aQObject*as its second parameter. So you need to haveEhinherit fromQObject.Try something like this: