Important: Please read the Qt Code of Conduct -

How to write a webkit application where a javascript will invoke a QT C++ methods?

  • I am writing a QT application - console one on the QT creator on FC19 machine. The aim here is to call a QT method from a javascript.

    At the moment, I am following this link -

    I am facing two problems -

    First compilation -

    /home/joshis1/Demo_JS/main.cpp:2: error: QWebElement: No such file or directory
    #include <QWebElement>

    #include <QCoreApplication>
    #include <QWebElement>

    class MyObject : QObject {

    public slots:
        void doSomethingWithWebElement(const QWebElement&);
    /* ... */

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    MyObject myObject;
    myWebPage.mainFrame()->addToJavaScriptWindowObject("myObject", &myObject);
    return a.exec&#40;&#41;;


    Here is the pro file -


    Project created by QtCreator 2014-02-08T17:31:01


    QT += core

    QT -= gui

    TARGET = Demo_JS
    CONFIG += console
    CONFIG -= app_bundle
    QT += webkit

    TEMPLATE = app

    SOURCES += main.cpp

    The next upcoming challenge I thinks is how to relate a javascript present in any folder of my FC19 to invoke a QT function defined in the above program. How my javascript will know the path to pick the application. How it can be done? This is my javascript wrapped in a html file.

    function runExample() {
    <body >
    <span id="someElement">Text</span>

    Please help me here with an elaborate explanation. I am literally frustrated with all my trials.

Log in to reply