0

Hello I made a HTML5 Application with QtCreator using QT5.

My main.cpp looks like the following:

#include <QApplication>
#include "html5applicationviewer.h"

#include "sqlfunctions.h"

int main(int argc, char *argv[])
{
    sqlfunctions* obj = new sqlfunctions;

    QApplication app(argc, argv);

    Html5ApplicationViewer viewer;
    viewer.setOrientation(Html5ApplicationViewer::ScreenOrientationAuto);
    viewer.showExpanded();
    viewer.loadFile(QLatin1String("src/index.html"));
    viewer.setFixedSize(1200, 900);

    return app.exec();
}

What i want to achieve is calling a C++ function to manipulate a SQL-Database, when for instance the user clicks on a button.

So basically i need something like the following (jQuery-shorthand):

$(document).ready(function(){
    $("#button").click(function(){
        mycppfunction();
    });
};)

I already read in the documentation and this thread about the problem and the method addToJavascriptWindowObject(). However since I do not have a QWebView or QWebFrame, how i can actually achieve the same functionality, or rebuild the app to work as described.

Community
  • 1
  • 1
Alex
  • 751
  • 1
  • 6
  • 34
  • 1
    The `Html5ApplicationViewer` class should contain the `QWebFrame` or similar, did you have a look at this class already? – m.s. May 10 '15 at 11:12
  • I can't seem to find any documentation on it :( – Alex May 10 '15 at 11:32
  • how about looking at its header file? – m.s. May 10 '15 at 12:15
  • since you found the relevant code according [to your follow up question](http://stackoverflow.com/questions/30177675/qt-expose-any-c-object-to-javascript), you might want to post an answer here. – m.s. May 11 '15 at 21:39

1 Answers1

0

The code you would want to add, in order to make this work is the following

QWebFrame *frame = viewer.webView()->page()->mainFrame();
QString objJavascriptName = "myObj";
frame->addToJavaScriptWindowObject(objJavascriptName, &obj);

Add this after Html5ApplicationViewer viewer;

Alex
  • 751
  • 1
  • 6
  • 34