Results 1 to 3 of 3

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    1
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

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

    I am looking for a short example with a minute details covered.

    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/

    Iam facing two problems -

    First compilation -


    /home/joshis1/Demo_JS/main.cpp:2: error: QWebElement: No such file or directory
    Qt Code:
    1. #include <QWebElement>
    2.  
    3. #include <QCoreApplication>
    4. #include <QWebElement>
    5.  
    6. class MyObject : QObject {
    7. Q_OBJECT
    8.  
    9. public slots:
    10. void doSomethingWithWebElement(const QWebElement&);
    11. };
    12.  
    13. /* ... */
    14.  
    15.  
    16. int main(int argc, char *argv[])
    17. {
    18. QCoreApplication a(argc, argv);
    19.  
    20. MyObject myObject;
    21. myWebPage.mainFrame()->addToJavaScriptWindowObject("myObject", &myObject);
    22.  
    23.  
    24. return a.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 
    Here is the pro file.
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2014-02-08T17:31:01
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core
    8.  
    9. QT -= gui
    10.  
    11. TARGET = Demo_JS
    12. CONFIG += console
    13. CONFIG -= app_bundle
    14. QT += webkit
    15.  
    16. TEMPLATE = app
    17.  
    18.  
    19. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    The next upcoming challenge I thinks is how to relate a java script 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 java script wrapped in a html file.
    Qt Code:
    1. <html>
    2. <head>
    3. <script>
    4. function runExample() {
    5. myObject.doSomethingWithWebElement(document.getElementById("someElement"));
    6. }
    7. </script>
    8. </head>
    9. <body onload="runExample()">
    10. <span id="someElement">Text</span>
    11. </body>
    12. </html>
    To copy to clipboard, switch view to plain text mode 
    Please help me here with an elaborate explanation. I am literally frustrated with all my trials.
    Last edited by anda_skoa; 9th February 2014 at 13:36. Reason: added code tags

Similar Threads

  1. ActiveX-javascript invoke activex interface exception
    By zhy282289 in forum Qt Programming
    Replies: 0
    Last Post: 29th October 2012, 02:58
  2. Webkit open new javascript Page
    By ShapeShiftme in forum Qt Programming
    Replies: 3
    Last Post: 25th October 2012, 08:46
  3. Webkit and Javascript Debugger
    By ideru in forum Installation and Deployment
    Replies: 1
    Last Post: 7th October 2011, 04:14
  4. Replies: 10
    Last Post: 10th February 2011, 19:45
  5. WebKit - accessing javascript results + googleMap
    By giusepped in forum Qt Programming
    Replies: 10
    Last Post: 30th May 2009, 00:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.