| Adobe Flash: from the Web into a Qt |
|
|
|
In this section, we explain the benefits of using Qtitan components for the Qt framework and provide valuable usage tips. A component package called Qtitan Multimedia enables Qt developers to tightly integrate various multimedia components, such as Adobe Flash, Microsoft Silverlight movies or Adobe Reader documents, into their applications. Last time, we integrated a Silverlight banner into a Qt application. Not only did we make the banner show up in a desktop application, but also integrated it on a fairly low level:
More details can be found in our previous post here: Integrating Silverlight into Qt applications. Today, we’ll talk about setting up a “working relationship” with Flash movies. Adobe FlashWe hope there is no need to explain what Flash is. Some associate it with ubiquitous annoying banners, some with browser games, some with Flash videos on various “tube” sites. One fact is obvious – Flash is everywhere, it has conquered the Internet. It’s still hard to tell what benefits this migration of offline apps to the web may bring us. One thing is clear, though – desktop apps are alive and will be around for a good while. So while the industry giants are busy making regular apps go online, we’ll do the exact opposite – we’ll apply the most advanced Internet technologies in our small and modest desktop Qt application. Creating an exampleHere what we’ll need for a sample integration of a Flash movie into a Qt application:
What are we going to do today? We’ll create a user interface entirely built in Flash that will interact with a Qt application. The second part of our example will deal with a reverse task – sending data from a Qt application to a Flash movie. Creating a Flash movieAdobe Flash Builder provides everything necessary for creating Flash applications using the Flex technology. Flex is a large set of classes (Flex SDK) containing many components that were not originally included in Flash. The cool thing about Flex is its declarative MXML interface description language that is structurally very similar to XML. If we compare it with Microsoft Silverlight, we’ll see that MXML and Silverlight have an almost identical purpose. We work with XAML last time and now we’ll spend some time with MXML. As the result, we have a project ready to be worked on. On the left hand side, in the Package Explorer window, is the project tree. Below the project tree is the Components window with a selection of available interface elements. The center of the window is a work area where our Rich Internet Application will be created. Creating an interface is very easy – just drag the elements from the Components tab to the work area and align them on the layout. Here we applied the Zen style to our application. Form components have the following names (IDs):
Our next step is the creation of a click handler. Let’s pick a button in the designer and select the Generate Event Handler option in the On Click field on the Properties tab. We’ll create the following button click handler: protected function btnSubmit_clickHandler(event:MouseEvent):void Here we collect the input field values from the form and pass them to the call function of the ExternalInterface object. The first parameter of the call function will be the name of a JavaScript function called “Submit”. It is followed by the function arguments. In fact, the “Submit” function will be simulated by our Qt application, but everything will look like regular work with regular JavaScript functions on the side of the Flash movie. We could actually start integrating the movie into our Qt application at this point. However, just to make sure we don’t need to go back to the Flash Builder again, we’ll fulfill the reverse task – that of passing data from the application to the movie. Let’s open the source code of the movie and add an extra function to the CDATA section. private function init():void We’ll add an external container callback function that will enable us to call this function from our Qt application. private function submit(arg1:String, arg2:String, arg3:String, arg4:String, arg5:String):void
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="init();"
For now, we are done working with the Flash move, so let’s export the results and proceed to creating a Qt application and integrating the Flash movie into it. You can export the result of your work from Adobe Flash Builder using the Project -> Export Release Build command. Creating a Qt application
TEMPLATE = app include($$(QTITANDIR)/src/shared/shared.pri) Let’s add our movie called FlashForm.swf to the resource file: <!DOCTYPE RCC><RCC version="1.0">
class MainWindow : public QMainWindow
We use this class to define a static function called submitFromFlash intended for fetching data from the Flash movie. We define a submit() slot, that will send data from the Qt application to the Flash movie. We’ll also need a getUrl() slot for interacting with the movie.
MainWindow::MainWindow(QWidget *parent) // Create a central object
Here we load our Flash movie in the same manner we did with Silverlight, register the Submit function to fetch data from the movie and create the user interface. The user interface is created in the form of a QTabWidget – one of the tabs will accommodate the Flash movie and the other one will have our Qt application. The interface is created by the makeWidget() function of the MainWindow class: QWidget * MainWindow::makeWidget()
QScriptValue MainWindow::submitFromFlash(QScriptContext* context, QScriptEngine *) Below is the code of the function that passes field values from the Qt app’s tab to the Flash movie. void MainWindow::submit() The only thing we still have to do is to write the code of the getUrl slot: void MainWindow::getUrl(NPluginStreamArgs& args) We can now pass data from the Flash App tab to the Qt App tab and vice versa.
ConclusionSo what’s the bottom line? As you can see, integrating a Flash application into a Qt application is even simpler than doing this with a Silverlight movie. On the Qt app’s side, there were almost no modifications – we only changed the object type from Qtitan::Silverlight to Qtitan::FlashPlayer. Therefore, you can develop interactive movies using any platform, Microsoft Silverlight or Adobe Flash – Qtitan Multimedia will work with either of them equally well.
|
Should you need any additional information about our products or licensing, please contact us at the following email addresses:
If you would like to purchase our products or services, but don’t know how to do it the right way, please feel free to contact us:
support@devmachines.com ( any questions related to our products or services )
license@devmachines.com ( questions related to licensing )