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. [Solved] How to pass data from Qt application to Javascript function?
Forum Updated to NodeBB v4.3 + New Features

[Solved] How to pass data from Qt application to Javascript function?

Scheduled Pinned Locked Moved Qt WebKit
4 Posts 2 Posters 3.8k Views 1 Watching
  • 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.
  • Z Offline
    Z Offline
    zither
    wrote on last edited by
    #1

    Dear all friends,

    Qt Application

    @ QString from;
    QFile file( ":/test.js");
    if ( !file.open(QIODevice::ReadOnly | QIODevice::Text) )
    {
    from = "Hello!";
    QString functions = file.readAll();
    QWebFrame* frame = ui->webView->page()->mainFrame();
    frame->evaluateJavaScript( functions );

    QString script = QString("myFunction(%1);").arg( from );
    frame->evaluateJavaScript(script);
    }
    

    @

    Is there somethings wrong with my function call?

    Thanks

    Here is test.js

    @ function myFunction (from)

    {
     
    alert("This is testing... ");
    alert(from);
     
    }@
    
    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      It would most likely be simpler to just stick an QObject into the JS context via "QWebFrame::addToJavaScriptWindowObject(...)":http://doc.qt.nokia.com/4.7-snapshot/qwebframe.html#addToJavaScriptWindowObject and interact over that one.

      This works better when you have the JS under your control:-)

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zither
        wrote on last edited by
        #3

        Could you show me some details or links.. please..

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          I am sure you will find some using your search engine of choice.

          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