Summary of Qt Webkit embedded Flash (Mac platform)

Source: Internet
Author: User

Qt WebkitEmbeddedFlashThe summary is what we will introduce in this article. We all know thatFlashIt is a closed-source product of adobe. Rendering on various platforms is achieved throughPlug-insFor example, in windowsFlash. Ocx, libflashplugin. so in linux and Flash_Plugin in mac ),Plug-insIt can be obtained on adobe's website.

Of course, there are also open source such as gnash) or commercial projects such as scaleform) fromFlashDecoding and rendering. I use qtwebkit to embed flash mainly because it is relatively simple. If you want to embed a web page in the game, of course, flash is also included. In addition to expensive scaleform, you can also choose other flash guis. However, it is not highly practical because of efficiency, the principle is to use the adobe plug-in to obtain each frame of the image to be rendered, and then render it to a texture for rendering through the engine. To put it bluntly, the game engine is used instead of windows or qt for rendering.

1. There are a lot of relevant information on the Internet. Here we only talk about the principles and key things)

To load flash for display, the page is also included), in fact, you only need to create a QWebView and then call its setUrl interface to transfer the path of the file to be displayed, preferably the absolute path, and add file before the path: ///, of course, this should not be necessary ). Another important interface of QWebView is setHtml, which transmits a string parameter and changes the string to the source code form of the html webpage, such as "

If you want to interact with each other, you need to use javascript to transfer data. In principle, you can use the NP Api to directly interact with the flash plug-in provided by adobe. However, there are too few materials, I have not written any plug-ins, so I chose a simple method ).

Here, I chose to embed flash in a webpage and add js scripts in the webpage's

Here are some notes:

1) it is critical that you use addToJavaScriptWindowObject to load the dom. We recommend that you use a function to call addToJavaScriptWindowObject and change the signal of javaScriptWindowObjectCleared to connect. For details, refer to the comment on the addToJavaScriptWindowObject function in QWebFrame.

2) c ++ calls js functions: page ()-> mainFrame ()-> evaluateJavaScript ("Test (1, 2 )"), in this way, you can directly call the Test function in js, where 1 and 2 are parameters.

3) js calls the c ++ function: Make sure that step a has been operated. Then, in js, you can directly use addToJavaScriptWindowObject to pass in the object name to call the function of the corresponding QObject object.

4) js calls the flash function: You can use ExternalCallback directly after as2.0. Here, the old method is used to be compatible with the previous flash. Assume that a flash file has been inserted in the webpage, and its id is flashname. Use flashname. SetVariable to modify the variables in flash. In the flash script, the watch () method is used to monitor the change of this variable and call the corresponding function.

5) flash calls js functions: fscommand functions are used in flash. In js, flash name_dofscommand (cmd, args) can be automatically called.

6) passFlash(Especially Chinese strings) if it is unicode encoded, otherwise it will be garbled.

Finally, the interaction steps, especially when js calls the flash function, are also important. If it is earlier, it may be necessary to wait until the flash function is fully loaded ), maybe the new method will be better. Here I use a very disgusting implementation. Create a timer, once a second to confirm that flash has been loaded), allow to call this function.

2. qt webkit bug:

In fact, it may also be the flash plug-in bug of adobe, but there is a problem anyway. Fortunately, webkit is open-source and I have to modify it. (Of course, there is no perfect bug fixing in the end, but it satisfies the needs of Nokia. It is enough to hope that Nokia's elites can solve the problem at the next release)

Bug Description: In the mac operating system, flash is loaded using qtwebkit. when entering the text box, press the next key to return two characters.

Cause: I guess it's in adobe 10.1.Plug-insI implemented the input response myself. Even if I filtered out all the key messages, flash still could normally input the messages, including the Chinese ones), and qtwebkit sent it another key information, this problem occurs.

Solution: this file is used in pluginViewMac. mmqt.) The dispatchNPevent function filters out key messages.

  1. if (event.what == keyDown)  {   
  2. return ;  

In this way, the flash Input is normal. Of course, no other plug-ins can be entered normally. However, it is enough to serve a flash plug-in instead of a browser.

Another bug is that if I click in the blank area of the web page and return to the flash text box, I cannot enter it normally, even if the cursor is inside, unless I find a text box in flash and click it. It is preliminarily determined that the reason is that when you click a blank area, the whole webkit page will not be able to obtain the key information, because a page cannot be edited, unless you click to a text box, in this way, you can obtain the input information again. If the entire page does not receive the key informationFlashPlug-ins naturally cannot be entered. However, sadly, if we had previously shielded PluginView's keyDown information, we would normally enter a character at this time. Of course, Chinese characters still cannot be normally entered.

These two bugs will continue to be checked for two days, and there may be new discoveries.

Summary: AboutQt WebkitEmbeddedFlashSummary of Mac platform). I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.