Trick To Get Qt QWebView Bridge Accessible from Webkit IFRAME (Local Pages)

后端 未结 1 394
感情败类
感情败类 2021-01-23 02:02

My Qt C++ (Qt 5.5) application uses a QWebView widget. After a lot of confusion and hard work, I have managed to get the QtWebKit Bridge technique to work and now have my Webkit

相关标签:
1条回答
  • 2021-01-23 02:15

    There are three different techniques for a compromise:

    Option A

    HTML5 supports a postMessage() API to transfer messages from children IFRAME documents to their parent documents, and it works even with local pages (like with file://). This is a little slower because it's an indirect technique of message passing and interpretation.

    Option B

    Unlike your Chrome browser with its security controls on pages accessed with file://, Qt's version of WebKit will let you call window.parent.foo() if the parent document contains a function foo(). From there, you can call the cpp object to do tasks. This is slightly indirect, but not as indirect as the postMessage() API.

    Option C

    If the parent document has an object called cpp (your C++ injected object that you created, as an example), Qt's version of WebKit will let you call var cpp = window.parent.cpp; in order for the IFRAME to have access to the cpp.

    One extra suggestion I would have is, if you're testing a WebKit interface in Chrome before being deployed through Qt, you could use an if (window.parent.cpp) (iframe document) and an if (cpp) (parent document) in order to determine if this is loading through Qt or Chrome, and then, if loaded through Chrome, fake a result through a Javascript file (like a kind of polyfill) just so that your Chrome GUI tests work okay until you're ready to hook it up to the C++ in Qt.

    0 讨论(0)
提交回复
热议问题