Call and interact with QT and flex SWF

Source: Internet
Author: User

 

  1. Add config to the project file XXXX. Pro

    + = Qaxcontainer

  2. Use the following code in the window to embed and play the flash
    <Br/> // Chinese encoding Settings <br/> qtextcodec: setcodecfortr (qtextcodec: codecforname ("GBK ")); <br/> // <br/> qstring applicationpath = qcoreapplication: applicationdirpath (); <br/> SWF = new qaxwidget (0, 0 ); <br/> // The Show method should be placed here. Otherwise, a problem occurs when the SWF is initialized and the size is incorrect. <br/> SWF-> show (); <br/> // <br/> SWF-> setcontrol (qstring: fromutf8 ("{d27cdb6e-ae6d-11cf-96b8-444553540000 }")); <br/> SWF-> dynamiccall ("loadmovie (INT, qstring)", 0, applicationpath + "/resources/main.swf "); <br/> SWF-> dynamiccall ("play ");

     

  • Let the QT program call the method in SWF:

    • Define a button in the main window of QT. The click event of the button is as follows:
    • Void mainwindow: on_pushbutton_clicked () <br/>{< br/> // qmessagebox: Warning (null, "warning", "On click", qmessagebox :: yes | qmessagebox: No, qmessagebox: Yes); <br/> qstring funname = "callwithexe"; <br/> qstring Arg = qobject: TR ("Oh! I am the content sent from QT to flex "); <br/> qstring callmethod = "<invoke name =/" "+ funname +"/"returntype =/" XML/"> <arguments> <string>" + Arg +" </string> </arguments> </invoke> "; <br/> SWF-> dynamiccall ("callfunction (string)", callmethod); <br/>}
    • The Interface Program defined in the flex as file is as follows:
      Private function Init (): void {<br/> // This is an external interface, so that C # Can call <br/> externalinterface. addcallback ("callwithexe", callwithexe); <br/>}

       

    • Define the Program Implementation Method in the flex as file
      Public Function callwithexe (STR: string): void {<br/> alert. Show (STR, "the content is displayed"); <br/>}
    • The above code snippet completes this scenario: There is a button in the main window of QT. After you click the button, an alert window is displayed in flex with the following content: Oh, I am the content that QT passes to flex.
    • Let SWF call methods in QT:

      • Define a button in flex. Access the methods in QT and obtain a returned value.
        Protected function button#clickhandler (Event: mouseevent): void <br/>{< br/> // todo auto-generated method stub <br/> If (externalinterface. available) {<br/> // alert. show ("externalinterface available. You can call the shell method ") <br/> // call the external program sayhello method, and input the method parameter" Hunk "to output the result returned by the method <br/> var strreturn: string = externalinterface. call ("sayhello", "Hunk", "Roamer"); <br/> alert. show (strreturn); <br/>}else {<br/> alert. show ("externalinterface is unavailable. ") <Br/>}< br/>}

         

      • Define a slot in QT and connect to the signal generated by the method from Flex. When as3 is running, externalinterface. Call in flex generates a signal in the form of flashcall (

        Qstring

        Qstring is the parameter "Hunk" and "Roamer" in the flex method ".

      • Define a slot, which is defined in the header file.
        Public slots: void sayhello (qstring message );

         

      • Connect a slot in the QT code
        // Link a slot so that the slot is used after being called in SWF <br/> connect (SwF, signal (flashcall (qstring), this, slot (sayhello (const qstring &)));

      • Implementation Methods in slot
        Void mainwindow: sayhello (qstring message) <br/>{< br/> qmessagebox: Warning (null, qobject :: TR ("content passed by SWF"), message, qmessagebox: Yes | qmessagebox: No, qmessagebox: Yes); <br/> qstring rtnstring = qobject:: TR ("<string> oh yes! I am the content returned by QT </string> "); <br/> SWF-> dynamiccall (" setreturnvalue (string) ", rtnstring); <br/>}

        Note: The passed content in Flex is an XML containing the method name and parameter list. Similarly, if you want QT to return values to the flex code. The returned value must also be an XML string (

        "<String> oh, too! I am the content returned by QT </string>"

        ;

        ). Otherwise

    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: info-contact@alibabacloud.com 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.