Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. How to write a webkit application where a javascript will invoke a QT C++ methods?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Qt WebKit
1 Posts 1 Posters 869 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shreyas
    wrote on last edited by
    #1

    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 -

    http://qt.developpez.com/doc/4.7/qtwebkit-bridge/

    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 {
    Q_OBJECT

    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.

    <html>
    <head>
    [removed]
    function runExample() {
    myObject.doSomethingWithWebElement(document.getElementById("someElement"));
    }
    [removed]
    </head>
    <body >
    <span id="someElement">Text</span>
    </body>
    </html>

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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved